]> git.lizzy.rs Git - plan9front.git/blob - sys/src/libc/port/nrand.c
libregexp: improve the transition to next available thread, instruction, and generation
[plan9front.git] / sys / src / libc / port / nrand.c
1 #include        <u.h>
2 #include        <libc.h>
3
4 #define MASK    0x7fffffffL
5
6 int
7 nrand(int n)
8 {
9         long slop, v;
10
11         if(n < 0)
12                 return n;
13         if(n == 1)
14                 return 0;
15         /* and if n == 0, you deserve what you get */
16         slop = MASK % n;
17         do
18                 v = lrand();
19         while(v <= slop);
20         return v % n;
21 }