Skip to content

API reference / @jsprismarine/worldgen / XoroshiroRandomSource

Class: XoroshiroRandomSource ​

Defined in: random/XoroshiroRandomSource.ts:120

A RandomSource running Xoroshiro128++ over 32-bit lanes.

Bit-for-bit equal to Xoroshiro128PlusPlus, which stays the slow reference this is tested against; the lanes avoid a BigInt allocation per operation, which matters because the aquifer and the ore vein rule build one of these per visited cell.

Implements ​

Constructors ​

Constructor ​

new XoroshiroRandomSource(seedLo, seedHi): XoroshiroRandomSource

Defined in: random/XoroshiroRandomSource.ts:150

Parameters ​

seedLo ​

bigint

seedHi ​

bigint

Returns ​

XoroshiroRandomSource

Methods ​

consumeCount() ​

consumeCount(rounds): void

Defined in: random/XoroshiroRandomSource.ts:275

Advances the stream by rounds draws without returning them.

Parameters ​

rounds ​

number

Returns ​

void

Implementation of ​

RandomSource.consumeCount


fork() ​

fork(): RandomSource

Defined in: random/XoroshiroRandomSource.ts:280

Returns an independent stream seeded from this one, advancing this one.

Returns ​

RandomSource

Implementation of ​

RandomSource.fork


forkPositional() ​

forkPositional(): PositionalRandomFactory

Defined in: random/XoroshiroRandomSource.ts:285

Returns a positional factory seeded from this stream, advancing it.

Returns ​

PositionalRandomFactory

Implementation of ​

RandomSource.forkPositional


nextBits() ​

nextBits(bits): number

Defined in: random/XoroshiroRandomSource.ts:217

Returns the high bits from the next output without constructing a 64-bit bigint.

Parameters ​

bits ​

number

Returns ​

number


nextBoolean() ​

nextBoolean(): boolean

Defined in: random/XoroshiroRandomSource.ts:251

Returns the next boolean, taken from one bit of the stream.

Returns ​

boolean

Implementation of ​

RandomSource.nextBoolean


nextDouble() ​

nextDouble(): number

Defined in: random/XoroshiroRandomSource.ts:263

Returns the next value in [0, 1) with 53 bits of precision.

Returns ​

number

Implementation of ​

RandomSource.nextDouble


nextFloat() ​

nextFloat(): number

Defined in: random/XoroshiroRandomSource.ts:257

Returns the next value in [0, 1) with 24 bits of precision.

Returns ​

number

Implementation of ​

RandomSource.nextFloat


nextGaussian() ​

nextGaussian(): number

Defined in: random/XoroshiroRandomSource.ts:269

Returns the next normally distributed value with mean 0 and standard deviation 1.

Returns ​

number

Implementation of ​

RandomSource.nextGaussian


nextInt() ​

nextInt(): number

Defined in: random/XoroshiroRandomSource.ts:228

Returns the next 32-bit signed integer, with every value equally likely.

Returns ​

number

Implementation of ​

RandomSource.nextInt


nextIntBounded() ​

nextIntBounded(bound): number

Defined in: random/XoroshiroRandomSource.ts:234

Returns the next integer in [0, bound).

Parameters ​

bound ​

number

Returns ​

number

Throws ​

When bound is not positive, as Java does.

Implementation of ​

RandomSource.nextIntBounded


nextLong() ​

nextLong(): bigint

Defined in: random/XoroshiroRandomSource.ts:211

Returns the next 64-bit signed integer.

Returns ​

bigint

Implementation of ​

RandomSource.nextLong


restoreState() ​

restoreState(state): void

Defined in: random/XoroshiroRandomSource.ts:180

Restores this source from a JSON-parsed state, rejecting invalid lanes and fixed points.

Parameters ​

state ​

unknown

Returns ​

void


saveState() ​

saveState(): XoroshiroRandomSourceState

Defined in: random/XoroshiroRandomSource.ts:166

Returns the four unsigned state lanes and cached Gaussian value for replay.

Returns ​

XoroshiroRandomSourceState


fromLanes() ​

static fromLanes(loHi, loLo, hiHi, hiLo): XoroshiroRandomSource

Defined in: random/XoroshiroRandomSource.ts:140

Builds a source from a 128-bit state given as four unsigned 32-bit lanes.

Parameters ​

loHi ​

number

loLo ​

number

hiHi ​

number

hiLo ​

number

Returns ​

XoroshiroRandomSource


fromSeed() ​

static fromSeed(seed): XoroshiroRandomSource

Defined in: random/XoroshiroRandomSource.ts:135

Builds a source from a world seed, spreading it to 128 bits the way Java does.

Parameters ​

seed ​

bigint

Returns ​

XoroshiroRandomSource


fromState() ​

static fromState(state): XoroshiroRandomSource

Defined in: random/XoroshiroRandomSource.ts:130

Builds a source from a 128-bit state, which fork and the positional factory produce.

Parameters ​

state ​

Seed128bit

Returns ​

XoroshiroRandomSource