git: 9front

ref: ac4840116ef15e2fc65d0e68f7e16d3a8a1aa2f8
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;
}