Skip to content
CShift0.32

Random

Struct · namespace System · Since 0.04

struct Random

Pseudo-random numbers (xorshift64*, seeded with SplitMix64). The same seed always gives the same sequence, on every system - useful for tests, procedural content and replays. Not suitable for cryptography.

var random = Random.Create(42);
int die = random.Next(1, 7); // 1..6
double x = random.NextDouble(); // [0, 1)

A Random is a value: a copy continues independently from the same state.

Name Description
Create A generator that starts from seed: the same seed always gives the same sequence (any seed works, also 0).
static Random Create(int64 seed)

A generator that starts from seed: the same seed always gives the same sequence (any seed works, also 0).

static Random Create()

Seeded from the clock: a different sequence on every run.

Name Description
NextBits The next 64 random bits.
Next A number from 0 to int.MaxValue - 1.
NextDouble A number in [0, 1).
NextBool true or false, each with a probability of one half.
uint64 NextBits()

The next 64 random bits.

int Next()

A number from 0 to int.MaxValue - 1.

int Next(int max)

A number from 0 to max - 1 (0 if max <= 0).

int Next(int min, int max)

A number from min to max - 1 (min if max <= min).

double NextDouble()

A number in [0, 1).

bool NextBool()

true or false, each with a probability of one half.