Skip to content
Ilia Petrov-Komotskii edited this page Sep 30, 2026 · 1 revision

Unity-backed IRandom and sampling helpers. Domain ManeRandom, GlobalRandom, and dice live in the ManeTools-dotNET wiki.

GlobalRandom.SetInstance(new UnityRandom(seed)) installs this generator as the shared source.

UnityRandom

Implements Mane.DotNet.IRandom using UnityEngine.Random, but each instance keeps its own Random.State, so it does not disturb the global RNG. All instances share one lock around that swap: overlapping draws cannot interleave Random.state. A raw UnityEngine.Random call from another thread during a draw is still outside that lock.

using Mane.DotNet;
using Mane.Unity;

IRandom rng = new UnityRandom(12345); // or new UnityRandom() for a crypto seed
float t = rng.Range01();
int i = rng.Next(0, 10);

Sampling

All take IRandom (null throws on direction helpers).

Color c = RandomColor.Color(rng);          // opaque RGB
Color32 c32 = RandomColor.Color32(rng);

Vector2 p = RandomPoint.Point2D(rng);      // [0, 1)²
Vector3 q = RandomPoint.OnVector3D(a, b, rng); // t in [0, 1), end excluded

Vector2 dir2 = RandomDirection.OnCircle(rng);
Vector3 dir3 = RandomDirection.OnSphere(rng);

Clone this wiki locally