Add most of libsec.
This commit is contained in:
parent
768206abfc
commit
0fc65b37a1
47 changed files with 9625 additions and 0 deletions
23
src/libsec/port/nfastrand.c
Normal file
23
src/libsec/port/nfastrand.c
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
#include <u.h>
|
||||
#include <libc.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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue