3 rand, lrand, frand, nrand, lnrand, srand, truerand, ntruerand, genrandom, prng, fastrand, nfastrand \- random number generators
32 ulong ntruerand(ulong val)
36 .B #include <libsec.h>
39 void genrandom(uchar *buf, int nbytes)
42 void prng(uchar *buf, int nbytes)
48 ulong nfastrand(ulong val)
51 returns a uniform pseudo-random
54 .if t 0≤ \fIx\fR <2\u\s715\s10\d.
61 .if t 0≤ \fIx\fR <2\u\s731\s10\d.
71 twice to generate a number with as many as 62 significant bits of mantissa.
74 returns a uniform integer
78 is the same, but returns a
81 The algorithm is additive feedback with:
83 x[n] = (x[n\(mi273] + x[n\(mi607]) mod
88 .if t 2\u\s730\s10\d \(mu (2\u\s7607\s10\d \- 1).
89 .if n 2^30 × (2^607 - 1).
91 The generators are initialized by calling
93 with whatever you like as argument.
94 To get a different starting value each time,
99 will work as long as it is not called more often
100 than once per second.
106 will initialize the generators to their
110 returns a random unsigned long read from
114 truerand can only return a few hundred bits a
118 returns a uniform random integer
120 .if t 0≤ \fIx\fR < \fIval\fR ≤ 2\u\s732\s10\d-1.
121 .if n 0≤ x < val ≤ 2^32-1.
124 fills a buffer with bytes from the X9.17 pseudo-random
125 number generator. The X9.17 generator is seeded by 24
126 truly random bytes read from
132 pseudo-random number generator to fill the buffer. Used with
134 this function can produce a reproducible stream of pseudo random
135 numbers useful in testing.
152 .if t 0≤ \fIx\fR <2\u\s732\s10\d-1.
161 .if t 0≤ \fIx\fR < \fIval\fR ≤ 2\u\s732\s10\d-1.
162 .if n 0≤ x < val ≤ 2^32-1.
164 .B /sys/src/libc/port/*rand.c
166 .B /sys/src/libc/9sys/truerand.c
168 .B /sys/src/libsec/port/genrandom.c
170 .B /sys/src/libsec/port/prng.c
172 .B /sys/src/libsec/port/*fastrand.c
180 maintain a static file descriptor.