Skip to content

KernelAPI reference

Class SeededRandom

Namespace: MicroEngine.Kernel
Assembly: MicroEngine.Kernel.dll
Guide: Modules and the frame schedule

A Random that draws exactly what new Random(seed) draws, and whose state can take part in the per-step state hash (IStateHashed): its seed, how many values it drew and a running hash of them. Two runs that drew the same values from the same seed hash the same; one extra or different draw changes the hash.

C#
public sealed class SeededRandom : Random, IStateHashed

Inheritance

object ← Random ← SeededRandom

Implements

IStateHashed

Inherited Members

Random.Next(), Random.Next(int), Random.Next(int, int), Random.NextInt64(), Random.NextInt64(long), Random.NextInt64(long, long), Random.NextSingle(), Random.NextDouble(), Random.NextBytes(byte[]), Random.NextBytes(Span<byte>), Random.GetItems<T>(ReadOnlySpan<T>, Span<T>), Random.GetItems<T>(T[], int), Random.GetItems<T>(ReadOnlySpan<T>, int), Random.Shuffle<T>(T[]), Random.Shuffle<T>(Span<T>), Random.GetString(ReadOnlySpan<char>, int), Random.GetHexString(int, bool), Random.GetHexString(Span<char>, bool), Random.Shared, object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

Remarks

The game’s own generator (Game.Random) is one. Use one wherever simulation draws from a generator of its own (new SeededRandom(seed) instead of new Random(seed)) and add it from the owner’s HashState.

Constructors

SeededRandom(int)

Creates a generator that draws the sequence of new Random(seed).

C#
public SeededRandom(int seed)

Parameters

seed int

Properties

Draws

How many values (or byte buffers) were drawn so far.

C#
public long Draws { get; }

Property Value

long

Seed

The seed the generator started from.

C#
public int Seed { get; }

Property Value

int

Methods

HashState(StateHasher)

Adds the seed, the number of draws and the running hash of the values drawn.

C#
public void HashState(StateHasher hash)

Parameters

hash StateHasher

Next()

C#
public override int Next()

Returns

int

Next(int)

C#
public override int Next(int maxValue)

Parameters

maxValue int

Returns

int

Next(int, int)

C#
public override int Next(int minValue, int maxValue)

Parameters

minValue int

maxValue int

Returns

int

NextBytes(byte[])

C#
public override void NextBytes(byte[] buffer)

Parameters

buffer byte[]

NextBytes(Span<byte>)

C#
public override void NextBytes(Span<byte> buffer)

Parameters

buffer Span<byte>

NextDouble()

C#
public override double NextDouble()

Returns

double

NextInt64()

C#
public override long NextInt64()

Returns

long

NextInt64(long)

C#
public override long NextInt64(long maxValue)

Parameters

maxValue long

Returns

long

NextInt64(long, long)

C#
public override long NextInt64(long minValue, long maxValue)

Parameters

minValue long

maxValue long

Returns

long

NextSingle()

C#
public override float NextSingle()

Returns

float

Sample()

C#
protected override double Sample()

Returns

double