]> git.lizzy.rs Git - plan9front.git/blob - sys/src/ape/lib/v/nrand.c
ape: Add mkstemp to /sys/src/ape/lib/ap/gen/mkfile
[plan9front.git] / sys / src / ape / lib / v / nrand.c
1 #include <stdlib.h>
2
3 #define MASK    0x7FFFFFFFL
4 #define FRACT   (1.0 / (MASK + 1.0))
5
6 extern long lrand(void);
7
8 double
9 frand(void)
10 {
11
12         return lrand() * FRACT;
13 }
14
15 nrand(int n)
16 {
17         long slop, v;
18
19         slop = MASK % n;
20         do
21                 v = lrand();
22         while(v <= slop);
23         return v % n;
24 }