Repository navigation
Random
Ilia Petrov-Komotskii edited this page Sep 24, 2026
·
5 revisions
Seeded random source plus dice and coin helpers. All helpers take an IRandom so you can swap implementations (domain ManeRandom, Unity-backed UnityRandom from ManeTools-Unity, or a fake in tests).
using Mane.DotNet;
IRandom rng = new ManeRandom(42); // deterministic
int d20 = RandomDice.Roll20(rng); // 1..20 inclusive
bool heads = RandomCoin.Flip(rng);
float t = rng.Range01(); // [0, 1)| Member | Range |
|---|---|
Seed |
Stored seed |
Next(min, max) |
[min, max) — same as System.Random.Next
|
Range01() |
[0, 1) float |
Range01Double() |
[0, 1) double |
Wraps System.Random. Not thread-safe.
-
new ManeRandom(int seed)— deterministic. -
new ManeRandom()— seed fromRandomNumberGenerator(crypto).Seedstill exposes the chosen int.
Pass a null IRandom into dice/coin helpers and they throw ArgumentNullException.
RandomDice.Roll(sides, random) returns [1, sides] inclusive (sides >= 1). Presets: Roll4, Roll6, Roll8, Roll10, Roll12, Roll20.
RandomCoin.Flip(random) is Roll(2) == 1.
Unity-side sampling (RandomPoint, RandomColor, RandomDirection) is documented in the Unity wiki.
openupm add com.manefunction.tools-dotnet