Struct SeedSource
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. Internally, a seed source is a linear congruential generator (LCG) which tracks subsequent outputs based on additional seeds as its value.
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
seedGuidThe 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
seedintThe 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
seedobjectThe 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
seedfloatThe 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
seedstringThe 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()
public Random Random()
Returns
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.