Changeset 34933 in project


Ignore:
Timestamp:
12/14/17 10:40:47 (9 months ago)
Author:
felix
Message:

manual: updated random module page

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/man/5/Module (chicken random)

    r34052 r34933  
    22[[toc:]]
    33
    4 == Module (chicken process-context)
     4== Module (chicken random)
    55
    6 This module provides a ('''weak''') pseudo random number generator.
     6This module provides access to entropy (as provided by the operating
     7system) and a pseudo random number generator.
    78
    8 ==== randomize
     9On UNIX systems entropy is by default obtained from {{/dev/urandom}}.
     10On Linux, the {{getrandom(2)}} system call is used instead, if available.
     11On OpenBSD it is {{arc4random_buf(3)}}, on Windows {{RtlGenRandom}}.
    912
    10 <procedure>(randomize [SEED])</procedure>
     13The pseudo random number generator is an implementation of the
     14[[WELL512|https://en.wikipedia.org/wiki/Well_equidistributed_long-period_linear]] algorithm.
    1115
    12 Set random-number 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==== set-pseudo-random-seed!
     17
     18<procedure>(set-pseudo-random-seed! SEED [SIZE])</procedure>
     19
     20Set seed for the PRNG from the at most {{SIZE}} bytes of {{SEED}}.
     21which should be a byte vector or a string containing random data.
     22If {{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
     24state used by the PRNG, then it will necessarily be initialized in a less
     25random manner as possible.
    1526
    1627
    17 ==== random
     28==== pseudo-random-integer
    1829
    19 <procedure>(random N)</procedure>
     30<procedure>(pseudo-random-integer [RANGE])</procedure>
    2031
    21 Returns a pseudo-random {{integer}} in {{[0, N-1]}}. {{N}} is an {{integer}}.
     32Returns a uniformly distributed pseudo random integer between 0 and
     33{{RANGE-1}}, which may be a big integer.
    2234
    23 On Windows, {{N}} and the random value are {{exact integer}}.
    2435
    25 '''Warning''': This procedure uses ''rand(3)'' internally and exhibits
    26 its deficiencies, including low quality pseudo-randomness:
     36==== pseudo-random-real
    2737
    28 * On Windows and Solaris, only 32768 unique random values can be
    29 generated in the range {{[0, N-1]}}.  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 {{current-seconds}} 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>(pseudo-random-real)</procedure>
     39
     40Returns a uniformly distributed pseudo-random inexact number between
     410 and 1.
     42
     43
     44==== random-bytes
     45
     46<procedure>(random-bytes [BUF [SIZE]])</procedure>
     47
     48Returns random bytes from the available entropy source. If {{BUF}} is
     49given, 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}}
     51argument. If no arguments are given, {{random-bytes}} returns a
     52freshly allocated byte vector of sufficient size to be used as a seed
     53for {{set-pseudo-random-seed!}}.
     54
    3755
    3856---
Note: See TracChangeset for help on using the changeset viewer.