Soenneker.Utils.Random
4.0.130
Prefix Reserved
dotnet add package Soenneker.Utils.Random --version 4.0.130
NuGet\Install-Package Soenneker.Utils.Random -Version 4.0.130
<PackageReference Include="Soenneker.Utils.Random" Version="4.0.130" />
<PackageVersion Include="Soenneker.Utils.Random" Version="4.0.130" />
<PackageReference Include="Soenneker.Utils.Random" />
paket add Soenneker.Utils.Random --version 4.0.130
#r "nuget: Soenneker.Utils.Random, 4.0.130"
#:package Soenneker.Utils.Random@4.0.130
#addin nuget:?package=Soenneker.Utils.Random&version=4.0.130
#tool nuget:?package=Soenneker.Utils.Random&version=4.0.130
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.11)
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.SignalR.Web.Client
A resilient and dependable .NET SignalR web client |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.130 | 0 | 8/30/2026 |
| 4.0.129 | 13,372 | 8/29/2026 |
| 4.0.128 | 60,155 | 8/26/2026 |
| 4.0.127 | 145,731 | 8/11/2026 |
| 4.0.126 | 206,963 | 7/27/2026 |
| 4.0.125 | 221,648 | 7/16/2026 |
| 4.0.124 | 84,401 | 7/14/2026 |
| 4.0.123 | 194,497 | 6/18/2026 |
| 4.0.122 | 162,773 | 6/9/2026 |
| 4.0.120 | 113,365 | 6/5/2026 |
| 4.0.119 | 171,243 | 5/12/2026 |
| 4.0.118 | 164,103 | 4/23/2026 |
| 4.0.117 | 37,096 | 4/21/2026 |
| 4.0.116 | 109,464 | 4/14/2026 |
| 4.0.115 | 173,945 | 3/12/2026 |
| 4.0.110 | 107,391 | 3/10/2026 |
| 4.0.109 | 197 | 3/10/2026 |
| 4.0.108 | 64,664 | 3/9/2026 |
| 4.0.107 | 3,128 | 3/9/2026 |
| 4.0.106 | 118,843 | 3/4/2026 |
Clarify random distributions and stabilize weights