Table of Contents

Struct DeterministicRandom

Namespace
Core.Data
Assembly
Core.dll

Deterministic random number generator for multiplayer consistency Uses xorshift128+ algorithm for fast, high-quality random numbers Guarantees identical results across all platforms and clients

public struct DeterministicRandom

Constructors

DeterministicRandom(uint)

Create a new deterministic random generator with a seed

public DeterministicRandom(uint seed)

Parameters

seed uint

DeterministicRandom(uint4)

Create from an existing state

public DeterministicRandom(uint4 initialState)

Parameters

initialState uint4

Properties

State

Current state of the random number generator Can be serialized for save/load or network synchronization

public uint4 State { get; set; }

Property Value

uint4

Methods

Branch(uint)

Create a new random generator with different state (for sub-systems) This allows different systems to have independent random sequences while maintaining overall determinism

public DeterministicRandom Branch(uint offset = 1)

Parameters

offset uint

Returns

DeterministicRandom

FromSeedPhrase(string)

Create DeterministicRandom from seed phrase. Note: This is a simplified encoding - not full state recovery, but deterministic.

public static DeterministicRandom FromSeedPhrase(string phrase)

Parameters

phrase string

Returns

DeterministicRandom

GetStateHash()

Get a hash of the current state for verification

public uint GetStateHash()

Returns

uint

HasSameState(DeterministicRandom)

Verify two random generators have the same state

public bool HasSameState(DeterministicRandom other)

Parameters

other DeterministicRandom

Returns

bool

NextBool()

Generate random boolean

public bool NextBool()

Returns

bool

NextBool(FixedPoint32)

Generate random boolean with specified probability

public bool NextBool(FixedPoint32 probability)

Parameters

probability FixedPoint32

Returns

bool

NextElementExceptIndices<T>(T[], params int[])

Select random element from array, excluding elements at specific indices.

public T NextElementExceptIndices<T>(T[] array, params int[] excludedIndices) where T : unmanaged

Parameters

array T[]
excludedIndices int[]

Returns

T

Type Parameters

T

NextElementExcept<T>(T[], T)

Select random element from array, excluding a specific element.

public T NextElementExcept<T>(T[] array, T excluded) where T : unmanaged, IEquatable<T>

Parameters

array T[]
excluded T

Returns

T

Type Parameters

T

NextElement<T>(NativeArray<T>)

Select random element from NativeArray

public T NextElement<T>(NativeArray<T> array) where T : unmanaged

Parameters

array NativeArray<T>

Returns

T

Type Parameters

T

NextElement<T>(T[])

Select random element from array

public T NextElement<T>(T[] array) where T : unmanaged

Parameters

array T[]

Returns

T

Type Parameters

T

NextFixed()

Generate random float in range [0, 1) Uses fixed-point arithmetic for deterministic results

public FixedPoint32 NextFixed()

Returns

FixedPoint32

NextFixed(FixedPoint32)

Generate random fixed-point value in range [0, max)

public FixedPoint32 NextFixed(FixedPoint32 max)

Parameters

max FixedPoint32

Returns

FixedPoint32

NextFixed(FixedPoint32, FixedPoint32)

Generate random fixed-point value in range [min, max)

public FixedPoint32 NextFixed(FixedPoint32 min, FixedPoint32 max)

Parameters

min FixedPoint32
max FixedPoint32

Returns

FixedPoint32

NextGaussian()

Generate random value from standard normal distribution (mean=0, stddev=1). Uses Box-Muller transform with fixed-point math for determinism.

public FixedPoint32 NextGaussian()

Returns

FixedPoint32

NextGaussian(FixedPoint32, FixedPoint32)

Generate random value from normal distribution with specified mean and standard deviation.

public FixedPoint32 NextGaussian(FixedPoint32 mean, FixedPoint32 stdDev)

Parameters

mean FixedPoint32
stdDev FixedPoint32

Returns

FixedPoint32

NextInt(int)

Generate random integer in range [0, max)

public int NextInt(int max)

Parameters

max int

Returns

int

NextInt(int, int)

Generate random integer in range [min, max)

public int NextInt(int min, int max)

Parameters

min int
max int

Returns

int

NextPercent(int)

Generate random boolean with percentage chance (0-100)

public bool NextPercent(int percent)

Parameters

percent int

Returns

bool

NextPoint(int2, int2)

Generate random 2D point within a rectangle

public int2 NextPoint(int2 min, int2 max)

Parameters

min int2
max int2

Returns

int2

NextPointInCircle(FixedPoint32)

Generate random 2D point within a circle (using rejection sampling)

public FixedPoint2 NextPointInCircle(FixedPoint32 radius)

Parameters

radius FixedPoint32

Returns

FixedPoint2

NextUInt()

Generate next random uint32 using xorshift128+ algorithm

public uint NextUInt()

Returns

uint

NextUInt(uint)

Generate random integer in range [0, max) Uses rejection sampling to avoid bias

public uint NextUInt(uint max)

Parameters

max uint

Returns

uint

NextUInt(uint, uint)

Generate random integer in range [min, max)

public uint NextUInt(uint min, uint max)

Parameters

min uint
max uint

Returns

uint

NextWeightedElement<T>(T[], FixedPoint32[])

Select random element from array using FixedPoint weights.

public T NextWeightedElement<T>(T[] elements, FixedPoint32[] weights) where T : unmanaged

Parameters

elements T[]
weights FixedPoint32[]

Returns

T

Type Parameters

T

NextWeightedElement<T>(T[], int[])

Select random element from array using weights. Higher weight = more likely to be selected.

public T NextWeightedElement<T>(T[] elements, int[] weights) where T : unmanaged

Parameters

elements T[]
weights int[]

Returns

T

Type Parameters

T

NextWeightedIndex(int[])

Select random index using weights (useful when you need the index, not the element).

public int NextWeightedIndex(int[] weights)

Parameters

weights int[]

Returns

int

SetSeed(uint)

Reset to a known state (for testing or save/load)

public void SetSeed(uint seed)

Parameters

seed uint

Shuffle<T>(NativeArray<T>)

Shuffle NativeArray in-place using Fisher-Yates algorithm

public void Shuffle<T>(NativeArray<T> array) where T : unmanaged

Parameters

array NativeArray<T>

Type Parameters

T

Shuffle<T>(T[])

Shuffle array in-place using Fisher-Yates algorithm

public void Shuffle<T>(T[] array) where T : unmanaged

Parameters

array T[]

Type Parameters

T

ToSeedPhrase()

Export current state as human-readable seed phrase. Format: 8 words encoding the full 128-bit state.

public string ToSeedPhrase()

Returns

string

ToString()

public override string ToString()

Returns

string