Random
Struct · namespace System · Since 0.04
struct RandomPseudo-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..6double x = random.NextDouble(); // [0, 1)A Random is a value: a copy continues independently from the same state.
Static methods
Section titled “Static methods”| Name | Description |
|---|---|
Create |
A generator that starts from seed: the same seed always gives the same sequence (any seed works, also 0). |
Create
Section titled “Create”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.
Methods
Section titled “Methods”| 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. |
NextBits
Section titled “NextBits”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).
NextDouble
Section titled “NextDouble”double NextDouble()A number in [0, 1).
NextBool
Section titled “NextBool”bool NextBool()true or false, each with a probability of one half.