Skip to main content

RandomState

A static class in Root.Township, the global namespace.

Static stack for Unity's global random state, so code can seed UnityEngine.Random for a block and restore it after. Use the returned IDisposable in a using.

Fields​

2 private and internal fields
MemberWhat it is
private static RandomState.Disposer disposerShared disposable that calls Pop.
private static Stack<Random.State> stackSaved random states.

Properties​

MemberWhat it is
static int Height { get; }How many states are pushed.

Methods​

MemberWhat it is
static Random.State GetState(int seed)Returns the random state a seed produces without changing the current state.
static Random.State Pop()Restores the previous random state and returns the one being replaced.
static IDisposable Push(int seed)Saves the current random state and switches to one from a seed or a given state. Disposing the result pops it.
static IDisposable Push(Random.State state)Saves the current random state and switches to one from a seed or a given state. Disposing the result pops it.
static IDisposable PushRandom()Pushes a state seeded from the current random sequence.