The Rx256 Object

The Rx256 Object

Rx256 exposes the Xoxhiro256+ random number generator to Javascript (Xoshiro is a mash-up of 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.


var xosh = new Rx256()

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.

Rx256 Properties

seed [nunber]


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.

Rx256 Methods



range [number]

Generate an integer value between 0 and range - 1. Example:

var xosh = new Rx256()
var num = xosh.nextint(25) // generate a random value between 0 and 24


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

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


Generate a floating-point value between 0 and 1. Example:

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