Soenneker.Utils.Random
4.0.135
Prefix Reserved
dotnet add package Soenneker.Utils.Random --version 4.0.135
NuGet\Install-Package Soenneker.Utils.Random -Version 4.0.135
<PackageReference Include="Soenneker.Utils.Random" Version="4.0.135" />
<PackageVersion Include="Soenneker.Utils.Random" Version="4.0.135" />
<PackageReference Include="Soenneker.Utils.Random" />
paket add Soenneker.Utils.Random --version 4.0.135
#r "nuget: Soenneker.Utils.Random, 4.0.135"
#:package Soenneker.Utils.Random@4.0.135
#addin nuget:?package=Soenneker.Utils.Random&version=4.0.135
#tool nuget:?package=Soenneker.Utils.Random&version=4.0.135
Soenneker.Utils.Random
Thread-safe convenience methods built on Random.Shared
Installation
dotnet add package Soenneker.Utils.Random
This package is for simulation, sampling, jitter, and other non-secret randomness. Random.Shared
is not cryptographically secure. Use RandomNumberGenerator for passwords, tokens, keys, salts,
or any value whose predictability affects security.
Numeric ranges
int index = RandomUtil.Next(5, 20); // [5, 20)
double sample = RandomUtil.NextDouble(5, 20); // [5, 20) for ordinary finite bounds
int anyInt = RandomUtil.NextInt32(); // full Int32 range
Next(int) and Next(min, max) use the same exclusive-upper-bound rules as System.Random.
NextDouble() returns [0, 1). The ranged double overload applies
sample * (maxValue - minValue) + minValue and does not validate reversed, NaN, or infinite bounds.
Decimal values
decimal highResolution = RandomUtil.NextDecimalUniform(5m, 20m);
decimal faster = RandomUtil.NextDecimal(5m, 20m, roundingDigits: 2);
NextDecimalUniform() produces a high-resolution discrete value in [0, 1). Its internal mapping
has a small modulo bias, so it should not be treated as mathematically exact uniform sampling.
The ranged overload scales that value into the requested interval.
NextDecimal converts a random double to decimal before scaling. Both ranged decimal methods can
round with Math.Round's default midpoint-to-even behavior; rounding can produce an endpoint that
the unrounded sample would not reach. Neither method validates that minimum is less than maximum.
Weighted selection
string selected = RandomUtil.WeightedRandomSelection(
new[] { "small", "medium", "large" },
new[] { 1.0, 3.0, 1.0 });
Selection probability is proportional to each weight. Items and weights must have the same nonzero count; weights must be finite and non-negative, with at least one positive value. Inputs are read during the call and should not be mutated concurrently.
Random delay
await RandomUtil.Delay(
minValue: 100,
maxValue: 500,
logger,
cancellationToken);
Delay values are milliseconds and use [minValue, maxValue), except equal bounds produce that
single value. Cancellation propagates. The optional logger records the chosen delay and canceled
waits at debug level.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
NuGet packages (7)
Showing the top 5 NuGet packages that depend on Soenneker.Utils.Random:
| Package | Downloads |
|---|---|
|
Soenneker.Extensions.String
A collection of useful string extension methods |
|
|
Soenneker.Extensions.Enumerable
A collection of helpful enumerable extension methods |
|
|
Soenneker.Utils.Delay
A utility library for generic time delay related operations |
|
|
Soenneker.Extensions.List
A collection of helpful list extension methods |
|
|
Soenneker.GitHub.Repositories.PullRequests
Retrieves, reviews, rebases, and merges GitHub pull requests across repositories |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.135 | 7,468 | 9/24/2026 |
| 4.0.134 | 82,991 | 9/15/2026 |
| 4.0.133 | 88,413 | 9/13/2026 |
| 4.0.131 | 106,190 | 9/8/2026 |
| 4.0.130 | 265,236 | 8/30/2026 |
| 4.0.129 | 55,377 | 8/29/2026 |
| 4.0.128 | 120,326 | 8/26/2026 |
| 4.0.127 | 148,850 | 8/11/2026 |
| 4.0.126 | 207,303 | 7/27/2026 |
| 4.0.125 | 221,992 | 7/16/2026 |
| 4.0.124 | 84,463 | 7/14/2026 |
| 4.0.123 | 196,084 | 6/18/2026 |
| 4.0.122 | 163,039 | 6/9/2026 |
| 4.0.120 | 113,431 | 6/5/2026 |
| 4.0.119 | 172,303 | 5/12/2026 |
| 4.0.118 | 164,402 | 4/23/2026 |
| 4.0.117 | 37,131 | 4/21/2026 |
| 4.0.116 | 109,603 | 4/14/2026 |
| 4.0.115 | 176,263 | 3/12/2026 |
| 4.0.110 | 107,679 | 3/10/2026 |
Enable Native AOT compatibility analysis