tnrand.c - plan9port - [fork] Plan 9 from user space
HTML git clone git://src.adamsgaard.dk/plan9port
DIR Log
DIR Files
DIR Refs
DIR README
DIR LICENSE
---
tnrand.c (176B)
---
1 #include <lib9.h>
2
3 #define MASK 0x7fffffffL
4
5 int
6 nrand(int n)
7 {
8 long slop, v;
9
10 if(n < 0)
11 return n;
12 slop = MASK % n;
13 do
14 v = lrand();
15 while(v <= slop);
16 return v % n;
17 }