Skip to content

API reference / @jsprismarine/client / Random

Class: Random ​

Defined in: client/src/bot/Random.ts:14

A small, seeded pseudo-random generator.

Math.random() cannot be seeded, and a load run that cannot be repeated is not a measurement: two runs against the same server have to differ because the server behaved differently, not because the bots decided to walk somewhere else. Every choice a behavior makes comes from here.

Mulberry32 - thirty-two bits of state, a handful of operations, and a period long enough that a bot would have to run for weeks to notice it. The point is reproducibility, not cryptography, and nothing here should ever be used for the latter.

See ​

https://github.com/bryc/code/blob/master/jshash/PRNGs.md

Constructors ​

Constructor ​

new Random(seed): Random

Defined in: client/src/bot/Random.ts:17

Parameters ​

seed ​

number

Returns ​

Random

Methods ​

next() ​

next(): number

Defined in: client/src/bot/Random.ts:38

A float in [0, 1).

Returns ​

number


nextBoolean() ​

nextBoolean(probability?): boolean

Defined in: client/src/bot/Random.ts:56

Parameters ​

probability? ​

number = 0.5

Returns ​

boolean


nextFloat() ​

nextFloat(min, max): number

Defined in: client/src/bot/Random.ts:52

A float in [min, max).

Parameters ​

min ​

number

max ​

number

Returns ​

number


nextInt() ​

nextInt(min, max): number

Defined in: client/src/bot/Random.ts:47

An integer in [min, max].

Parameters ​

min ​

number

max ​

number

Returns ​

number


pick() ​

pick<T>(items): T

Defined in: client/src/bot/Random.ts:60

Type Parameters ​

T ​

T

Parameters ​

items ​

readonly T[]

Returns ​

T


forMember() ​

static forMember(seed, index): Random

Defined in: client/src/bot/Random.ts:31

A generator for one bot in a fleet, derived from the fleet's seed and the bot's index.

Derived rather than shared: one generator handed to five hundred bots would have them take turns drawing from a single sequence, so what each bot did would depend on how the others were scheduled - which is exactly the non-determinism the seed exists to remove.

Parameters ​

seed ​

number

index ​

number

Returns ​

Random