Table of Contents

Struct SeedSource

Namespace
MLEM.Maths
Assembly
MLEM.dll

A seed source contains an int value which can be used as a seed for a Random or SingleRandom. Seed sources feature a convenient way to add multiple seeds using Add(int), which will be sufficiently scrambled to be deterministically pseudorandom and combined into a single int. This struct behaves similarly to System.HashCode in many ways, with an important distinction being that SeedSource's scrambling procedure is not considered an implementation detail, and will stay consistent between process executions.

public readonly struct SeedSource
Inherited Members

Examples

For example, a seed source can be used to create a new Random based on an object's x and y coordinates by combining them into a SeedSource using Add(int). The values generated by the Random created using Random() will then be determined by the specific pair of x and y values used.

Methods

Add(Guid)

Adds the given seed to this seed source's value and returns the result as a new seed source. Guids are scrambled by invoking Add(int) using every byte in the Guid's byte array.

public SeedSource Add(Guid seed)

Parameters

seed Guid

The seed to add.

Returns

SeedSource

A new seed source with the seed added.

Add(int)

Adds the given seed to this seed source's value and returns the result as a new seed source. The algorithm used for adding involves various scrambling operations that sufficiently pseudo-randomize the seed and final value.

public SeedSource Add(int seed)

Parameters

seed int

The seed to add.

Returns

SeedSource

A new seed source with the seed added.

Add(object)

Adds the given seed to this seed source's value and returns the result as a new seed source. Any objects that don't have a specially defined Add(int) overload get scrambled using GetHashCode().

public SeedSource Add(object seed)

Parameters

seed object

The seed to add.

Returns

SeedSource

A new seed source with the seed added.

Add(float)

Adds the given seed to this seed source's value and returns the result as a new seed source. Floating point values are scrambled by invoking Add(int) using a typecast version, followed by invoking Add(int) using the decimal value multiplied by MaxValue.

public SeedSource Add(float seed)

Parameters

seed float

The seed to add.

Returns

SeedSource

A new seed source with the seed added.

Add(string)

Adds the given seed to this seed source's value and returns the result as a new seed source. Strings are scrambled by invoking Add(int) using every character contained in the string, in order.

public SeedSource Add(string seed)

Parameters

seed string

The seed to add.

Returns

SeedSource

A new seed source with the seed added.

Get()

Returns this seed source's seed value, which can then be used in SingleRandom or elsewhere.

public int Get()

Returns

int

This seed source's value.

Random()

Returns a new Random() instance using this source seed's value, retrieved using Get().

public Random Random()

Returns

Random

A new Random() using this seed source's value.

Rotate()

Returns a new seed source whose value is this seed source's value, but scrambled further. In essence, this creates a new seed source whose value is determined by the current seed source.

public SeedSource Rotate()

Returns

SeedSource

A new seed source with a rotated value.