diff options
Diffstat (limited to 'src/lib9/nrand.c')
-rw-r--r-- | src/lib9/nrand.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/lib9/nrand.c b/src/lib9/nrand.c new file mode 100644 index 00000000..cf9c17c3 --- /dev/null +++ b/src/lib9/nrand.c @@ -0,0 +1,17 @@ +#include <lib9.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; +} |