shithub: riscv

ref: f2a9244e2d5cf7011c07e5a3ea34c1fa032cae5c
dir: /sys/src/cmd/unix/drawterm/libc/nrand.c/

View raw version
#include	<u.h>
#include	<libc.h>

#define	MASK	0x7fffffffL

int
nrand(int n)
{
	long slop, v;

	if(n < 0)
		return n;
	slop = MASK % n;
	do
		v = lrand();
	while(v <= slop);
	return v % n;
}