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 .RI 0≤ x <2\u\s715\s10\d.
60 .RI 0≤ x <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 truerand can only return a few hundred bits a
116 returns a uniform random integer
118 .RI 0≤ x < val ≤ 2\u\s732\s10\d-1.
121 fills a buffer with bytes from the X9.17 pseudo-random
122 number generator. The X9.17 generator is seeded by 24
123 truly random bytes read from
129 pseudo-random number generator to fill the buffer. Used with
131 this function can produce a reproducible stream of pseudo random
132 numbers useful in testing.
149 .RI 0≤ x < 2\u\s732\s10\d-1.
157 .RI 0≤ x < val ≤ 2\u\s732\s10\d-1.
159 .B /sys/src/libc/port/*rand.c
161 .B /sys/src/libc/9sys/truerand.c
163 .B /sys/src/libsec/port/genrandom.c
165 .B /sys/src/libsec/port/prng.c
167 .B /sys/src/libsec/port/*fastrand.c
175 maintain a static file descriptor.