Files
9base/lib9/nrand.c
garbeam@wmii.de e5f0f74b8a initial import
2005-11-20 18:27:27 +02:00

20 lines
225 B
C

#include <lib9.h>
extern long p9lrand(void);
#define lrand p9lrand
#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;
}