Skip to content
Ilia Petrov-Komotskii edited this page Sep 24, 2026 · 5 revisions

Random

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)

IRandom

Member Range
Seed Stored seed
Next(min, max) [min, max) — same as System.Random.Next
Range01() [0, 1) float
Range01Double() [0, 1) double

ManeRandom

Wraps System.Random. Not thread-safe.

  • new ManeRandom(int seed) — deterministic.
  • new ManeRandom() — seed from RandomNumberGenerator (crypto). Seed still exposes the chosen int.

Pass a null IRandom into dice/coin helpers and they throw ArgumentNullException.

Dice and coin

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.

Clone this wiki locally