blob: 7394a132315f76e1e02d88f68415aaa58182a282 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include "os.h"
#include <libsec.h>
#define Maxrand ((1UL<<31)-1)
ulong
nfastrand(ulong n)
{
ulong m, r;
/*
* set m to the maximum multiple of n <= 2^31-1
* so we want a random number < m.
*/
if(n > Maxrand)
sysfatal("nfastrand: n too large");
m = Maxrand - Maxrand % n;
while((r = fastrand()) >= m)
;
return r%n;
}
|