Module sfmt

SIMD-oriented Fast Mersenne Twister (SFMT).

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

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()

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-bit X = [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()

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

This type represents an internal state for random number generator.

randlist()

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()

w128() = [integer()]

An 128-bit integer represented by four 32-bit unsigned integers. Note: the number of elements is four (4).

Function Index

gen_rand32/1generates a 32-bit random number from the given ran_sfmt().
gen_rand32_max/2generates a 32-bit random number from the given ran_sfmt() or intstate() where the 1st argument is Max and the range is [0, (Max - 1)].
gen_rand_all/1filling the internal state array with SFMT PRNG.
gen_rand_float/1generates a float random number from the given ran_sfmt() or intstate() where the range is (0.0, 1.0).
gen_rand_list32/2generating the 32-bit integer list of PRNG, where length of the list is Size with the updated internal state.
gen_rand_list_float/2generating a list of uniform floats of (0.0, 1.0) 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_list_max/2converts an internal state table to a list of N32 32-bit integers, where each list member is in the range between [0, (Max - 1)].
intstate_to_randlist/1converts an internal state table to a list of N32 32-bit integers.
intstate_to_randlist_float/1converts an internal state table to a list of [0.0, 1.0] float.
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.
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_rand32_max/2

gen_rand32_max(Max::integer(), RS::{[integer()], intstate()} | intstate()) -> {integer(), {[integer()], intstate()}}

generates a 32-bit random number from the given ran_sfmt() or intstate() where the 1st argument is Max and the range is [0, (Max - 1)].

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

gen_rand_float(RS::ran_sfmt() | intstate()) -> {float(), ran_sfmt()}

generates a float random number from the given ran_sfmt() or intstate() where the range is (0.0, 1.0). (Note: once nifnized, but the speed of list-based code is faster)

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.

gen_rand_list_float/2

gen_rand_list_float(Size::integer(), Intstate::intstate()) -> {[float()], intstate()}

generating a list of uniform floats of (0.0, 1.0) 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_list_max/2

intstate_to_list_max(Max::integer(), Intstate::intstate()) -> [integer()]

converts an internal state table to a list of N32 32-bit integers, where each list member is in the range between [0, (Max - 1)]. (Note: NIFnized)

To ensure the equal probability of generation for each integer value between [0, (Max - 1)], the list of integers are generated by the following algorithm: Note: the number of the list members is smaller or equal to N32 (624).

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)

intstate_to_randlist_float/1

intstate_to_randlist_float(Intstate::intstate()) -> [float()]

converts an internal state table to a list of [0.0, 1.0] float. (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.

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.

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(N::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.


Generated by EDoc, Jan 13 2016, 10:41:52.