Add most of libsec.

This commit is contained in:
rsc 2004-03-21 14:04:56 +00:00
parent 768206abfc
commit 0fc65b37a1
47 changed files with 9625 additions and 0 deletions

View 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;
}