3 rand, lrand, frand, nrand, lnrand, srand, truerand, ntruerand, genrandom, prng, fastrand, nfastrand \- random number generators
32 ulong ntruerand(ulong val)
34 .B #include <libsec.h>
37 void genrandom(uchar *buf, int nbytes)
40 void prng(uchar *buf, int nbytes)
46 ulong nfastrand(ulong val)
49 returns a uniform pseudo-random
52 .if t 0≤ \fIx\fR <2\u\s715\s10\d.
59 .if t 0≤ \fIx\fR <2\u\s731\s10\d.
69 twice to generate a number with as many as 62 significant bits of mantissa.
72 returns a uniform integer
76 is the same, but returns a
79 The algorithm is additive feedback with:
81 x[n] = (x[n\(mi273] + x[n\(mi607]) mod
86 .if t 2\u\s730\s10\d \(mu (2\u\s7607\s10\d \- 1).
87 .if n 2^30 × (2^607 - 1).
89 The generators are initialized by calling
91 with whatever you like as argument.
92 To get a different starting value each time,
97 will work as long as it is not called more often
104 will initialize the generators to their
108 returns a random unsigned long read from
112 returns a uniform random integer
114 .if t 0≤ \fIx\fR < \fIval\fR ≤ 2\u\s732\s10\d-1.
115 .if n 0≤ x < val ≤ 2^32-1.
118 fills a buffer with bytes from the cryptographic pseudo-random
119 number generator. The generator is automatically seeded by
125 pseudo-random number generator to fill the buffer. Used with
127 this function can produce a reproducible stream of pseudo random
128 numbers useful in testing.
145 .if t 0≤ \fIx\fR <2\u\s732\s10\d-1.
154 .if t 0≤ \fIx\fR < \fIval\fR ≤ 2\u\s732\s10\d-1.
155 .if n 0≤ x < val ≤ 2^32-1.
157 .B /sys/src/libc/port/*rand.c
159 .B /sys/src/libc/9sys/truerand.c
161 .B /sys/src/libsec/port/genrandom.c
163 .B /sys/src/libsec/port/prng.c
165 .B /sys/src/libsec/port/*fastrand.c
173 maintain a static file descriptor.