new XOR128(xopt) → {XOR128}
XOR128 pseudo-random number generator.
Formerly based on the implementation by WizCorp https://github.com/Wizcorp/xor128/,
now based on the xor128 as described on Wikipedia https://en.wikipedia.org/wiki/Xorshift
All parameters are optional, if nothing is passed a random value from
js functions Math.random() will be used
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
x |
number | Array |
<optional> |
null | seed or array of seeds. \ If an array is passed, the first 4 elements will be used as seeds |
Throws:
-
if x is not a number or an array of 4 numbers
- Type
- Error
Returns:
- Type
- XOR128
Methods
pick() → {*}
Returns a random item from the provided array or a random char from the provided string
Returns:
item from input array or char from input string
- Type
- *
random(aopt, bopt) → {number}
Returns a random number in range [a, b) (i.e. a included, b excluded)
If only one parameter is passed, the random number will be generated in range [0, a)
If no parameters are passed, the random number will be generated in range [0, 1)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
a |
number | undefined |
<optional> |
if two parameters are passed, minimum range value; maximum range value otherwise |
b |
number | undefined |
<optional> |
maximum range value |
Returns:
random number
- Type
- number
random_bool() → {boolean}
Returns a random boolean
Returns:
random boolean
- Type
- boolean
random_from_array(arr) → {*}
Returns a random item from the provided array
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | an array |
Returns:
item from input array
- Type
- *
random_from_string(str) → {string}
Returns a random char from the provided string
Parameters:
Name | Type | Description |
---|---|---|
str |
string | a string |
Returns:
char from input string
- Type
- string
random_int(aopt, bopt) → {number}
Returns a random integer in range [a, b) (i.e. a included, b excluded)
If only one parameter is passed, the random number will be generated in range [0, a)
If no parameters are passed, the random number will be generated in range [0, 1]
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
a |
number | undefined |
<optional> |
if two parameters are passed, minimum range value; maximum range value otherwise |
b |
number | undefined |
<optional> |
maximum range value |
Returns:
random number
- Type
- number
random_interval(averageopt, intervalopt) → {number}
Returns a random integer in range (average - interval, average + interval)
If only one parameter is passed, the random number will be generated in range (average - 0.5, average + 0.5)
If no parameters are passed, the random number will be generated in range [0, 1]
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
average |
number |
<optional> |
0.5 | average value of the random numbers |
interval |
number |
<optional> |
0.5 | semi interval of the random numbers |
Returns:
random number
- Type
- number
random_string(lengthopt, charsopt)
Returns a random string
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
length |
number |
<optional> |
10 | length of the string |
chars |
string |
<optional> |
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" | characters to use |
shuffle(x) → {*}
Shuffles and returns an array or a string.
Parameters:
Name | Type | Description |
---|---|---|
x |
Array | string | an array or a string |
Returns:
shuffled array or string
- Type
- *
shuffle_array(arr)
Shuffles the provided array (the original array does not get shuffled)
Parameters:
Name | Type | Description |
---|---|---|
arr |
Array | an array |
shuffle_string(string) → {string}
Shuffles and returns a string
Parameters:
Name | Type | Description |
---|---|---|
string |
string | the string to be shuffled |
Returns:
- Type
- string