Search                        Top                                  Index
HELP RANDOM_STATES                               John Williams, Oct 1986

The library package LIB * RANDOM_STATES creates a record class called
"random_state". Such objects encapsulate the state of a pseudo random
number generator. When applied to a number N, a random_state returns a
random number M where M >= 0 and M <= N. Random_states can be copied;
the original and the copy produce identical series of numbers if applied
to the same arguments.

Objects of the POP11 class "random_state" are identical to objects of
the Common Lisp type RANDOM-STATE.

The following functions operate on random_states:

    consrandom_state(<integer | false:I>) -> <random_state>
        Constructs a random_state object, with 'seed' value initialised
        to I. If I is -false-, the seed is given some randomly chosen
        value

    destrandom_state(<random_state>) -> <integer | false>
        Stacks the components of <random_state>, i.e. the 'seed' value

    israndom_state(<item>) -> <boolean>
        -true- if <item> is a random_state, -false- otherwise

    random_seed(<random_state>) -> <integer | false>
        <integer | false> -> random_seed(<random_state>)
        Returns/updates the 'seed' of the given <random_state>

    apply_random_state(<integer | float:N>, <random_state>)
                                    -> <integer | float:M>)
        Returns a random number M where M >= 0 and M <= N
        This procedure is the -class-apply- of random_state objects


The key of random_state objects is held in the constant 'random_state_key'


-- Example -------------------------------------------------------------

    vars r = consrandom_state(false);
    r =>
    ** <random_state <false>>

    repeat 3 times r(100) => endrepeat;
    ** 47
    ** 50
    ** 82

    define nextfrom(n, state);
        copy(state)(n)
    enddefine;

    nextfrom(100, r) =>
    ** 86

    r(100) =>
    ** 86

-- See also ------------------------------------------------------------

HELP * RANDOM
REF * NUMBERS

-----<Copyright University of Sussex 1986.  All rights reserved.>-------