table of contents
other versions
- jessie-backports 1:19.2.1+dfsg-2+deb9u1~bpo8+1
- stretch 1:19.2.1+dfsg-2+deb9u2
- testing 1:21.2.6+dfsg-1
- unstable 1:21.2.6+dfsg-1
- experimental 1:22.0~rc1+dfsg-1
other sections
rand(3erl) | Erlang Module Definition | rand(3erl) |
NAME¶
rand - Pseudo random number generation.DESCRIPTION¶
This module provides a random number generator. The module contains a number of algorithms. The uniform distribution algorithms use the scrambled Xorshift algorithms by Sebastiano Vigna. The normal distribution algorithm uses the Ziggurat Method by Marsaglia and Tsang. The following algorithms are provided:- exsplus:
- Xorshift116+, 58 bits precision and period of 2^116-1
- exs64:
- Xorshift64*, 64 bits precision and a period of 2^64-1
- exs1024:
- Xorshift1024*, 64 bits precision and a period of 2^1024-1
R0 = rand:uniform(), R1 = rand:uniform(),Use a specified algorithm:
_ = rand:seed(exs1024), R2 = rand:uniform(),Use a specified algorithm with a constant seed:
_ = rand:seed(exs1024, {123, 123534, 345345}), R3 = rand:uniform(),Use the functional API with a non-constant seed:
S0 = rand:seed_s(exsplus), {R4, S1} = rand:uniform_s(S0),Create a standard normal deviate:
{SND0, S2} = rand:normal_s(S1),
Note:
This random number generator is not cryptographically strong. If a strong
cryptographic random number generator is needed, use one of functions in the
crypto module, for example,
crypto:strong_rand_bytes/1.
DATA TYPES¶
alg() = exs64 | exsplus | exs1024state()
Algorithm-dependent state.
export_state()
Algorithm-dependent state that can be printed or saved to file.
EXPORTS¶
export_seed() -> undefined | export_state()
Returns the random number state in an external format. To be used with
seed/1.
export_seed_s(X1 :: state()) -> export_state()
Returns the random number generator state in an external format. To be used with
seed/1.
normal() -> float()
Returns a standard normal deviate float (that is, the mean is 0 and the standard
deviation is 1) and updates the state in the process dictionary.
normal_s(State0 :: state()) -> {float(), NewS :: state()}
Returns, for a specified state, a standard normal deviate float (that is, the
mean is 0 and the standard deviation is 1) and a new state.
seed(AlgOrExpState :: alg() | export_state()) -> state()
Seeds random number generation with the specifed algorithm and time-dependent
data if AlgOrExpState is an algorithm.
Otherwise recreates the exported seed in the process dictionary, and returns the
state. See also export_seed/0.
seed(Alg :: alg(), S0 :: {integer(), integer(), integer()}) -> state()
Seeds random number generation with the specified algorithm and integers in the
process dictionary and returns the state.
seed_s(AlgOrExpState :: alg() | export_state()) -> state()
Seeds random number generation with the specifed algorithm and time-dependent
data if AlgOrExpState is an algorithm.
Otherwise recreates the exported seed and returns the state. See also
export_seed/0.
seed_s(Alg :: alg(), S0 :: {integer(), integer(), integer()}) -> state()
Seeds random number generation with the specified algorithm and integers and
returns the state.
uniform() -> X :: float()
Returns a random float uniformly distributed in the value range 0.0 < X
< 1.0 and updates the state in the process dictionary.
uniform(N :: integer() >= 1) -> X :: integer() >= 1
Returns, for a specified integer N >= 1, a random integer uniformly
distributed in the value range 1 <= X <= N and updates the state
in the process dictionary.
uniform_s(State :: state()) -> {X :: float(), NewS :: state()}
Returns, for a specified state, random float uniformly distributed in the value
range 0.0 < X < 1.0 and a new state.
uniform_s(N :: integer() >= 1, State :: state()) -> {X :: integer() >= 1, NewS :: state()}
Returns, for a specified integer N >= 1 and a state, a random integer
uniformly distributed in the value range 1 <= X <= N and a new
state.
stdlib 3.2 | Ericsson AB |