class Rx256

Xoxhiro256+ random number generator

Rx256 exposes the Xoxhiro256+ random number generator to Javascript (Xoshiro is a mash-upof XOR + Shift + Rotate). This random number generator is very efficient and has excellent statistical properties (a uniform distribution) for both integer and floating-point applications. You can also seed it for repeatable results.

Index

Constructors

Properties

Methods

new Rx256()

new Rx256();

Create a Rx256 random number generator

Unlike Math::random, before you generate a random value with Xoshiro256+, you must create a new Rx256 object that will hold the state of the random number generator. Particularly if you want a repeatable sequence of numbers, it's important to have separate Rx256 objects to hold the state for each place you want to use a sequence of random values.

nextfloat_bipolar()

Generate a floating-point value between -1 and 1.

nextfloat_bipolar(): number;
NameTypeDescription
Return Valuenumber

Example

var xosh = new Rx256();
var num = xosh.nextfloat_bipolar(); // generate a random value -1 and 1

nextfloat_unipolar()

Generate a floating-point value between 0 and 1.

nextfloat_unipolar(): number;
NameTypeDescription
Return Valuenumber

Example

var xosh = new Rx256();
var num = xosh.nextfloat_unipolar(); // generate a random value 0 and 1

nextint(range)

Get the next random number in a given range.

The range is a positive integer that specifies the maximum value, and is not inclusive. For example, if you specify a range of 10, the random number will be between 0 and 9, inclusive.

nextint(range: number): number;
NameTypeDescription
rangenumber
Return Valuenumber

Example

var xosh = new Rx256();
var num = xosh.nextint(10); // generate a random value between 0 and 9

seed number

The seed for the random number generator.

Set the seed to a non-zero value to generate a repeatable sequence of values. By default, the seed is 0, which uses the system clock to seed the random number generator.