Class: XOR128

XOR128(xopt)

new XOR128(xopt)

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
Source:
Throws:
if x is not a number or an array of 4 numbers
Type
Error

Methods

pick(x) → {any}

Returns a random item from the provided array or a random char from the provided string
Parameters:
Name Type Description
x Array | string an array or a string
Source:
Returns:
item from input array or char from input string
Type
any

pick_from_array(arr) → {any}

Returns a random item from the provided array
Parameters:
Name Type Description
arr Array an array
Source:
Returns:
item from input array
Type
any

pick_from_string(str) → {string}

Returns a random char from the provided string
Parameters:
Name Type Description
str string a string
Source:
Returns:
char from input string
Type
string

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
Source:
Returns:
random number
Type
number

random_bool() → {boolean}

Returns a random boolean
Source:
Returns:
random boolean
Type
boolean

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
Source:
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. Default is 0.5
interval number <optional>
0.5 semi interval of the random numbers. Default is 0.5
Source:
Returns:
random number
Type
number

random_string(lengthopt, charsopt) → {string}

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. Default is A-Z, a-z, 0-9
Source:
Returns:
random string
Type
string

shuffle(x) → {*}

Shuffles and returns an array or a string. The original array or string does not get shuffled.
Parameters:
Name Type Description
x Array | string an array or a string
Source:
Returns:
shuffled array or string
Type
*

shuffle_array(arr) → {Array}

Shuffles the provided array. The original array does not get shuffled.
Parameters:
Name Type Description
arr Array an array
Source:
Returns:
shuffled array
Type
Array

shuffle_string(string) → {string}

Shuffles and returns a string. The original string does not get shuffled.
Parameters:
Name Type Description
string string the string to be shuffled
Source:
Returns:
shuffled string
Type
string