Constructor
new Random(seed, next) → {Random}
- Source:
Parameters:
Name | Type | Description |
---|---|---|
seed |
Number | |
next |
Method() |
Returns:
- Type
- Random
Methods
(static) next(bitsopt) → {Number}
- Source:
Generates the next pseudorandom number. This function is passed into constructor and other functions are using it to generate specific random values, so it essentially makes a pseudo-random generation engine.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
bits |
Number |
<optional> |
32
|
That many low-order bits of the returned value will be (approximately) independently chosen bit values, each of which is (approximately) equally likely to be 0 or 1. |
Returns:
- Type
- Number
(static) get_seed() → {Number}
- Source:
Returns current seed
Returns:
- Type
- Number
(static) set_seed(seed)
- Source:
Replaces current seed
Parameters:
Name | Type | Description |
---|---|---|
seed |
Number |
(static) next_bool() → {Bool}
- Source:
Return true or false
Returns:
The next pseudorandom, uniformly distributed boolean value from this random number generator's sequence.
- Type
- Bool
(static) next_double(nopt) → {Number}
- Source:
Return floating point value in range [ 0, n )
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
n |
Number |
<optional> |
1
|
Returns:
The next pseudorandom, uniformly distributed double-precission floating point value between 0.0 ( inclusive ) and n ( exclusive ) from this random number generator's sequence.
- Type
- Number
(static) next_float(nopt) → {Number}
- Source:
Return floating point value in range [ 0, n )
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
n |
Number |
<optional> |
1
|
Returns:
The next pseudorandom, uniformly distributed float value between 0.0 ( inclusive ) and n ( exclusive ) from this random number generator's sequence.
- Type
- Number
(static) next_int(nopt) → {Number}
- Source:
Return integer value in range [ 0, n )
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
n |
Number |
<optional> |
4294967296
|
Returns:
The next pseudorandom, uniformly distributed int value between 0 (inclusive) and n (exclusive) from this random number generator's sequence.
- Type
- Number
(static) next_int64() → {Number}
- Source:
Return integer value in range
Returns:
The next pseudorandom, uniformly distributed int64 value from this random number generator's sequence.
- Type
- Number
(static) range(startopt, stop, stepopt) → {Number}
- Source:
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
start |
Number |
<optional> |
0
|
|
stop |
Number | |||
step |
Number |
<optional> |
1
|
Returns:
- Type
- Number
(static) choice(iterable) → {Any}
- Source:
Fully consume iterable and return random element from it.
Parameters:
Name | Type | Description |
---|---|---|
iterable |
Iterable |
Returns:
random item from iterable
- Type
- Any
(static) choices(iterable, kopt) → {Any}
- Source:
Fully consume iterable and return k random elements with replacement.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
iterable |
Iterable | |||
k |
Number |
<optional> |
1
|
Returns:
random item from iterable
- Type
- Any
(static) choices_weighted(iterable, weights, kopt) → {Array}
- Source:
Fully consume iterable and return k random elements with replacement.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
iterable |
Iterable | |||
weights |
Iterable | |||
k |
Number |
<optional> |
1
|
Returns:
random items from iterable
- Type
- Array
(static) choices_weighted_cumulative(iterable, weights, kopt) → {Array}
- Source:
Fully consume iterable and return k random elements with replacement.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
iterable |
Iterable | |||
weights |
Iterable | cumulative weights |
||
k |
Number |
<optional> |
1
|
Returns:
random items from iterable
- Type
- Array
(static) sample(iterable, kopt) → {Array}
- Source:
Returns k non-repeating items from input iterable.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
iterable |
Iterable | |||
k |
Number |
<optional> |
1
|
Returns:
- Type
- Array
(static) sample_weighted(iterable, weights, kopt) → {Array}
- Source:
Returns k non-repeating items from input iterable.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
iterable |
Iterable | |||
weights |
Iterable | |||
k |
Number |
<optional> |
1
|
Returns:
- Type
- Array
(static) shuffle(iterable) → {Array}
- Source:
Returns shuffled array with items from input iterable. If iterable is array, shuffles the array itself.
Parameters:
Name | Type | Description |
---|---|---|
iterable |
Iterable |
Returns:
- Type
- Array
(static) exp_variate(labmda) → {Number}
- Source:
Exponential distribution.
Parameters:
Name | Type | Description |
---|---|---|
labmda |
Number | lambda is 1.0 divided by the desired mean. It should be nonzero. |
Returns:
- Type
- Number
(static) gaussian(muopt, sigmaopt) → {Number}
- Source:
Gaussian distribution.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
mu |
Number |
<optional> |
0
|
mean |
sigma |
Number |
<optional> |
1
|
standard deviation |
Returns:
- Type
- Number
(static) log_norm_variate(muopt, sigmaopt) → {Number}
- Source:
If you take the natural logarithm of this distribution, you'll get a normal distribution with mean mu and standard deviation sigma.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
mu |
Number |
<optional> |
0
|
mean |
sigma |
Number |
<optional> |
1
|
standard deviation. Sigma must be greater than zero. |
Returns:
- Type
- Number
(static) normal_variate(muopt, sigmaopt) → {Number}
- Source:
Normal distribution.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
mu |
Number |
<optional> |
0
|
mean |
sigma |
Number |
<optional> |
1
|
standard deviation |
Returns:
- Type
- Number
(static) pareto_variate(alpha) → {Number}
- Source:
Pareto distribution.
Parameters:
Name | Type | Description |
---|---|---|
alpha |
Number | Shape parameter. |
Returns:
- Type
- Number
(static) triangular(aopt, bopt, modeopt) → {Number}
- Source:
Return a random floating point number N such that a <= N <= b and with the specified mode between those bounds.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
a |
Number |
<optional> |
0
|
|
b |
Number |
<optional> |
1
|
|
mode |
Number |
<optional> |
(a+b)/2
|
Returns:
- Type
- Number
(static) uniform(a, b) → {Number}
- Source:
Return floating point value in range [ a, b ). Value b may or may not be included in this range depending on floating-point rounding.
Parameters:
Name | Type | Description |
---|---|---|
a |
Number | |
b |
Number |
Returns:
- Type
- Number
(static) von_mises_variate(mu, kappa) → {Number}
- Source:
Circular distribution
Parameters:
Name | Type | Description |
---|---|---|
mu |
Number | Mean angle, expressed in radians between 0 and 2*pi |
kappa |
Number | Concentration parameter, which must be greater than or equal to zero. If kappa is equal to zero, this distribution reduces to a uniform random angle over the range 0 to 2*pi. |
Returns:
- Type
- Number
(static) weibull_variate(_alpha, _beta) → {Number}
- Source:
Weibull distribution.
Parameters:
Name | Type | Description |
---|---|---|
_alpha |
Number | Scale parameter |
_beta |
Number | Shape parameter |
Returns:
- Type
- Number