Copyright © 2010-2016 Kenji Rikitake and Kyoto University. Copyright (c) 2006, 2007 Mutsuo Saito, Makoto Matsumoto and Hiroshima University.
Authors: Kenji Rikitake (kenji.rikitake@acm.org), Mutsuo Saito, Makoto Matsumoto, Dan Gudmundsson.
References
intstate() = binary()
A binary representation of N 128-bit integers for the internal state table, represented as multiple concatenation of four 32-bit unsigned integers. Note: the number of the binary bytes is the same as N32*4 (2496). Note well: intstate() is not portable among different host architectures due to the endianness issue. Use randlist() for transferring the internal state between the processes.
The Internal state format in details: list of 32-bit unsigned ints, with the following format of little-endian 128-bit format e.g., a 128-bitX = [X0, X1, X2, X3]
where in C
/* begin */
union X {
uint32_t u[4];
};
/* end */
and a 128-bit list is a flat concatenation
of 128-bit numbers.
ran_sfmt() = {non_neg_integer(), intstate()}
This type represents an internal state for random number generator.
randlist() = [integer()]
A list of N 128-bit integers for the portable representation of the internal state table, represented as multiple concatenation of four 32-bit unsigned integers. Note: the number of elements is the same as N32 (624).
w128() = [integer()]
An 128-bit integer represented by four 32-bit unsigned integers. Note: the number of elements is four (4).
gen_rand32/1 | generates a 32-bit random number from the given ran_sfmt(). |
gen_rand_all/1 | filling the internal state array with SFMT PRNG. |
gen_rand_list32/2 | generating the 32-bit integer list of PRNG, where length of the list is Size with the updated internal state. |
get_idstring/0 | returns SFMT identification string. |
get_lib_refc/0 | returns NIF library reference count. |
get_min_array_size32/0 | returns array size of internal state. |
init_by_list32/1 | generates an internal state from a list of 32-bit integers. |
init_gen_rand/1 | generates an internal state from an integer seed. |
intstate_to_randlist/1 | converts an internal state table to a list of N32 32-bit integers. |
randlist_to_intstate/1 | converts a valid internal state from a list of N32 32-bit integers. |
seed/0 | Initialize the process dictionary with seed0/0. |
seed/1 | Puts the seed computed from the given integer as a single-element list by init_by_list32/1 and puts the internal state into the process dictionary and initializes the random number list with the internal state and returns the old internal state. |
seed/3 | Puts the seed computed from given three integers and puts the internal state into the process dictionary and initializes the random number list with the internal state and returns the old internal state. |
seed0/0 | Returns the default internal state. |
uint32_to_float/1 | Converts a 32-bit unsigned integer N to a float number X where 0.0 < X < 1.0; X = (N + 0.5) * (1.0/4294967296). |
uniform/0 | Returns a uniformly-distributed float random number X where X is in the range of 0.0 < X < 1.0 and updates the internal state in the process dictionary. |
uniform/1 | Returns a uniformly-distributed integer random number X where X is in the range of 1 =< X =< N and updates the internal state in the process dictionary. |
uniform_s/1 | With a given state, Returns a uniformly-distributed float random number X and a new state where X is in the range of 0.0 < X < 1.0. |
uniform_s/2 | Returns a uniformly-distributed integer random number X and a new state where X is in the range of 1 =< X =< N. |
gen_rand32(RS::ran_sfmt() | intstate()) -> {integer(), ran_sfmt()}
generates a 32-bit random number from the given ran_sfmt(). (Note: once nifnized, but the speed of list-based code is faster)
gen_rand_all(Intstate::intstate()) -> intstate()
filling the internal state array with SFMT PRNG.
Recursion algorithm for gen_rand_all and gen_rand_list32:
a[]: output array (of S w128() elements)
i[]: internal state (of N w128() elements)
(For gen_rand_all, S =:= N)
(For gen_rand_list32, S >= N)
r(a, b, c, d): do_recursion/4 function (of 4 w128() arguments)
(The indexes are in C notation ([0 ... J-1] for J elements))
a[0] = r(i[0], i[POS1], i[N-2], i[N-1]);
a[1] = r(i[1], i[POS1+1], i[N-1], a[0]);
a[2] = r(i[2], i[POS1+2], a[0], a[1]);
...
a[(N-POS1)-1] = r(i[(N-POS1)-1], i[N-1], a[(N-POS1)-3], a[(N-POS1)-2]);
a[(N-POS1)] = r(i[(N-POS1)], a[0], a[(N-POS1)-2], a[(N-POS1)-1]);
a[(N-POS1)+1] = r(i[(N-POS1)+1], a[1], a[(N-POS1)-1], a[(N-POS1)]);
...
a[N-1] = r(i[N-1], a[POS1-1], a[N-3], a[N-2]);
% assignments from here only applicable to gen_rand_list32
a[N] = r(a[0], a[POS1], a[N-2], a[N-1]);
a[N+1] = r(a[1], a[POS1+1], a[N-1], a[N]);
...
a[X] = r(a[X-N], a[X-(N-POS1)], a[X-1], a[X-2]);
...
a[S-1] = r(a[(S-N)-1], a[S-(N-POS1)-1], a[S-2], a[S-3]);
Use the last N w128()
elements of a[]
for the new internal state ni[]
,
i.e.,
ni[0] = a[S-N], ni[1] = a[S-N+1], ... ni[N-1] = a[S-1].
gen_rand_list32(Size::integer(), Intstate::intstate()) -> {[integer()], intstate()}
generating the 32-bit integer list of PRNG, where length of the list is Size with the updated internal state.
get_idstring() -> string()
returns SFMT identification string. (Note: NIFnized)
get_lib_refc() -> integer()
returns NIF library reference count. (Note: NIFnized)
get_min_array_size32() -> integer()
returns array size of internal state. (Note: NIFnized)
init_by_list32(Seedlist::[integer()]) -> intstate()
generates an internal state from a list of 32-bit integers. (Note: NIFnized)
init_gen_rand(Seed::integer()) -> intstate()
generates an internal state from an integer seed. (Note: NIFnized)
intstate_to_randlist(Intstate::intstate()) -> randlist()
converts an internal state table to a list of N32 32-bit integers. (Note: NIFnized)
randlist_to_intstate(Randlist::randlist()) -> intstate()
converts a valid internal state from a list of N32 32-bit integers. (Note: NIFnized)
seed() -> ran_sfmt()
Initialize the process dictionary with seed0/0.
seed(N::integer() | [integer()] | {integer(), integer(), integer()}) -> ran_sfmt()
Puts the seed computed from the given integer as a single-element list by init_by_list32/1 and puts the internal state into the process dictionary and initializes the random number list with the internal state and returns the old internal state.
seed(A1::integer(), A2::integer(), A3::integer()) -> ran_sfmt()
Puts the seed computed from given three integers and puts the internal state into the process dictionary and initializes the random number list with the internal state and returns the old internal state.
seed0() -> ran_sfmt()
Returns the default internal state.
uint32_to_float(N::0..4294967295) -> float()
Converts a 32-bit unsigned integer N to a float number X where 0.0 < X < 1.0; X = (N + 0.5) * (1.0/4294967296).
uniform() -> float()
Returns a uniformly-distributed float random number X where X is in the range of 0.0 < X < 1.0 and updates the internal state in the process dictionary.
uniform(N::integer()) -> integer()
Returns a uniformly-distributed integer random number X where X is in the range of 1 =< X =< N and updates the internal state in the process dictionary. Note: the pigeonhole principle is applied to the output; this function will retry generating the base 32-bit unsigned integer number sequence if the result does not guarantee the equally-probabilistic results between the given range of integers.
uniform_s(RS::ran_sfmt()) -> {float(), ran_sfmt()}
With a given state, Returns a uniformly-distributed float random number X and a new state where X is in the range of 0.0 < X < 1.0.
uniform_s(Max::integer(), RS::ran_sfmt()) -> {integer(), ran_sfmt()}
Returns a uniformly-distributed integer random number X and a new state where X is in the range of 1 =< X =< N. Note: the pigeonhole principle is applied to the output; this function will retry generating the base 32-bit unsigned integer number sequence if the result does not guarantee the equally-probabilistic results between the given range of integers.
Generated by EDoc