Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ProwlEngine/Prowl.Vector/llms.txt
Use this file to discover all available pages before exploring further.
RNG is a high-quality, non-cryptographic pseudo-random number generator in the Prowl.Vector namespace, based on the xoshiro256** algorithm by David Blackman and Sebastiano Vigna. It provides a broad API covering basic numeric types, vector types, geometric sampling, Gaussian and exponential distributions, collections, and color generation. All range methods are inclusive of both endpoints.
Declaration
Algorithm
xoshiro256** (by David Blackman and Sebastiano Vigna) uses a 256-bit state (fourulong values) and applies a star-star scrambler on output. It has:
- Period: 2²⁵⁶ − 1
- Speed: extremely fast (no division in the hot path)
- Quality: passes all known statistical tests (BigCrush, PractRand)
Static Members
Shared
RNG instance seeded from the current time. Convenient for one-off calls; not thread-safe for concurrent access. Create separate RNG instances per thread for parallel workloads.
Constructors
Time-seeded (default)
Environment.TickCount ^ DateTime.UtcNow.Ticks, providing a unique sequence on each run.
From a ulong seed
From an int seed
seed to ulong and delegates to the ulong constructor.
Seed Management
SetSeed
Basic Generation
NextFloat
float in [0, 1] (inclusive). Uses the upper 24 bits of the raw output for full single-precision mantissa coverage.
NextDouble
double in [0, 1] (inclusive). Uses the upper 53 bits for full double-precision mantissa coverage.
NextInt
int in [0, int.MaxValue].
NextUInt
uint in [0, uint.MaxValue].
NextLong
long in [0, long.MaxValue].
NextBool
true or false with equal probability (tests the least-significant bit of the raw output).
Range Methods
All range methods are inclusive of both min and max.Scalar ranges
- Integer overloads use rejection sampling to eliminate modulo bias.
- Float/double overloads scale
Next*()linearly:min + Next*() * (max - min).
Vector ranges
Vector Helpers
NextFloat2 / NextFloat3 / NextFloat4
NextDouble2 / NextDouble3 / NextDouble4
Geometry Helpers
OnUnitCircle
cos/sin.
InsideUnitCircle
OnUnitSphere
Acos(2v − 1) for uniform area distribution.
InsideUnitSphere
u^(1/3) (cube-root) for correct volumetric density.
Direction2D / Direction3D
Angle Helpers
Color Generation
NextColor
Float4. The first overload always sets alpha = 1.0. All RGB components are uniformly sampled in [0, 1].
NextColorWithAlpha
Float4 with all four components (RGBA) uniformly sampled in [0, 1].
NextColorHSV
Float2(min, max) where values are in [0, 1].
| Parameter | Description |
|---|---|
hueRange | Hue range — (0, 1) covers the full spectrum. |
saturationRange | Saturation range — (1, 1) for fully saturated colors. |
valueRange | Value (brightness) range — (0.5, 1) for medium to bright colors. |
Probability & Weighted Selection
Chance
true with the given probability in [0, 1]. Example: Chance(0.25f) is true 25% of the time.
WeightedChoice
weights with probability proportional to each weight. Throws ArgumentException if weights are null, empty, all zero, or contain negative values.
Collections
Choice<T>
array. Throws ArgumentException if the array is null or empty.
Shuffle<T>
array in place using the Fisher-Yates algorithm (O(n), unbiased).
Shuffled<T>
array. The original is not modified.
Statistical Distributions
NextGaussian
| Parameter | Default | Description |
|---|---|---|
mean | 0.0 | Mean (center) of the distribution. |
standardDeviation | 1.0 | Standard deviation (spread). |
NextExponential
lambda is the rate parameter (must be > 0). The mean of the distribution is 1 / lambda.
Utility
NextBytes
bytes with random data in chunks of 8 bytes using the raw ulong output.
NextString
length characters drawn from charset. Returns an empty string when length ≤ 0.
Code Example
Notes
RNGis a class (reference type). Multiple variables can reference the same instance.RNG.Sharedis not thread-safe. Use a per-threadRNGinstance for concurrent code:[ThreadStatic] private static RNG _threadRng = new RNG();- The
NextGaussianimplementation caches one value between calls. Do not use the sameRNGinstance from two threads without a lock, or the cached Gaussian value can be lost. - For cryptographically secure random bytes, use
System.Security.Cryptography.RandomNumberGeneratorinstead. - All integer
Rangemethods use rejection sampling to guarantee exact uniform distribution with no modulo bias.