Changeset 34933 in project
 Timestamp:
 12/14/17 10:40:47 (5 weeks ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

wiki/man/5/Module (chicken random)
r34052 r34933 2 2 [[toc:]] 3 3 4 == Module (chicken processcontext)4 == Module (chicken random) 5 5 6 This module provides a ('''weak''') pseudo random number generator. 6 This module provides access to entropy (as provided by the operating 7 system) and a pseudo random number generator. 7 8 8 ==== randomize 9 On UNIX systems entropy is by default obtained from {{/dev/urandom}}. 10 On Linux, the {{getrandom(2)}} system call is used instead, if available. 11 On OpenBSD it is {{arc4random_buf(3)}}, on Windows {{RtlGenRandom}}. 9 12 10 <procedure>(randomize [SEED])</procedure> 13 The pseudo random number generator is an implementation of the 14 [[WELL512https://en.wikipedia.org/wiki/Well_equidistributed_longperiod_linear]] algorithm. 11 15 12 Set randomnumber seed. If {{SEED}} (an {{exact integer}}) is not supplied, the 13 current time is used. On startup (when Unit {{extras}} is initialized), the 14 random number generator is initialized with the current time. 16 ==== setpseudorandomseed! 17 18 <procedure>(setpseudorandomseed! SEED [SIZE])</procedure> 19 20 Set seed for the PRNG from the at most {{SIZE}} bytes of {{SEED}}. 21 which should be a byte vector or a string containing random data. 22 If {{SIZE}} is not given, it defaults to the size of {{SEED}}. If {{SIZE}} 23 (or the size of {{SEED}}) is below the required size of the random 24 state used by the PRNG, then it will necessarily be initialized in a less 25 random manner as possible. 15 26 16 27 17 ==== random28 ==== pseudorandominteger 18 29 19 <procedure>( random N)</procedure>30 <procedure>(pseudorandominteger [RANGE])</procedure> 20 31 21 Returns a pseudorandom {{integer}} in {{[0, N1]}}. {{N}} is an {{integer}}. 32 Returns a uniformly distributed pseudo random integer between 0 and 33 {{RANGE1}}, which may be a big integer. 22 34 23 On Windows, {{N}} and the random value are {{exact integer}}.24 35 25 '''Warning''': This procedure uses ''rand(3)'' internally and exhibits 26 its deficiencies, including low quality pseudorandomness: 36 ==== pseudorandomreal 27 37 28 * On Windows and Solaris, only 32768 unique random values can be 29 generated in the range {{[0, N1]}}. If {{N >= 32768}}, there 30 will be gaps in the result set. 31 * On Mac OS X, Windows and some other platforms, little variance in output is seen 32 with nearby seeds. Since the random generator is seeded 33 with {{currentseconds}} at startup, new processes may see similar or 34 identical random sequences for up to a minute. 35 * On Linux, ''rand(3)'' is an alias to ''random(3)'', which provides 36 output of reasonable quality. 38 <procedure>(pseudorandomreal)</procedure> 39 40 Returns a uniformly distributed pseudorandom inexact number between 41 0 and 1. 42 43 44 ==== randombytes 45 46 <procedure>(randombytes [BUF [SIZE]])</procedure> 47 48 Returns random bytes from the available entropy source. If {{BUF}} is 49 given, it should be a string or byte vector which will be filled with up to 50 {{SIZE}} random bytes. {{SIZE}} defaults to the size of the {{BUF}} 51 argument. If no arguments are given, {{randombytes}} returns a 52 freshly allocated byte vector of sufficient size to be used as a seed 53 for {{setpseudorandomseed!}}. 54 37 55 38 56 
Note: See TracChangeset
for help on using the changeset viewer.