Module sfmt

SIMD-oriented Fast Mersenne Twister (SFMT).

Copyright © 2010-2021 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

Description

SIMD-oriented Fast Mersenne Twister (SFMT). The module provides skeleton functions for the NIFs and the interface functions. The module defines a PRNG of period ((2^19937) - 1).

Data Types

intstate()

intstate() = binary()

ran_sfmt()

ran_sfmt() = {non_neg_integer(), intstate()}

randlist()

randlist() = [integer()]

Function Index

gen_rand32/1generates a 32-bit random number from the given ran_sfmt().
gen_rand_all/1filling the internal state array with SFMT PRNG.
gen_rand_list32/2generating the 32-bit integer list of PRNG, where length of the list is Size with the updated internal state.
get_idstring/0returns SFMT identification string.
get_lib_refc/0returns NIF library reference count.
get_min_array_size32/0returns array size of internal state.
init_by_list32/1generates an internal state from a list of 32-bit integers.
init_gen_rand/1generates an internal state from an integer seed.
intstate_to_randlist/1converts an internal state table to a list of N32 32-bit integers.
randlist_to_intstate/1converts a valid internal state from a list of N32 32-bit integers.
seed/0Initialize the process dictionary with seed0/0.
seed/1Puts 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/3Puts 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/0Returns the default internal state.
uint32_to_float/1Converts 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/0Returns 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/1Returns 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/1With 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/2Returns a uniformly-distributed integer random number X and a new state where X is in the range of 1 =< X =< N.

Function Details

gen_rand32/1

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/1

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/2

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/0

get_idstring() -> string()

returns SFMT identification string. (Note: NIFnized)

get_lib_refc/0

get_lib_refc() -> integer()

returns NIF library reference count. (Note: NIFnized)

get_min_array_size32/0

get_min_array_size32() -> integer()

returns array size of internal state. (Note: NIFnized)

init_by_list32/1

init_by_list32(Seedlist::[integer()]) -> intstate()

generates an internal state from a list of 32-bit integers. (Note: NIFnized)

init_gen_rand/1

init_gen_rand(Seed::integer()) -> intstate()

generates an internal state from an integer seed. (Note: NIFnized)

intstate_to_randlist/1

intstate_to_randlist(Intstate::intstate()) -> randlist()

converts an internal state table to a list of N32 32-bit integers. (Note: NIFnized)

randlist_to_intstate/1

randlist_to_intstate(Randlist::randlist()) -> intstate()

converts a valid internal state from a list of N32 32-bit integers. (Note: NIFnized)

seed/0

seed() -> ran_sfmt()

Initialize the process dictionary with seed0/0.

seed/1

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/3

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/0

seed0() -> ran_sfmt()

Returns the default internal state.

uint32_to_float/1

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/0

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/1

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/1

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/2

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