tlnrand.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
---
tlnrand.c (194B)
---
1 #include <u.h>
2 #include <libc.h>
3
4 #define MASK 0x7fffffffL
5
6 long
7 lnrand(long n)
8 {
9 long slop, v;
10
11 if(n < 0)
12 return n;
13 slop = MASK % n;
14 do
15 v = lrand();
16 while(v <= slop);
17 return v % n;
18 }