NCode.Randomness
0.4.1
Prefix Reserved
See the version list below for details.
dotnet add package NCode.Randomness --version 0.4.1
NuGet\Install-Package NCode.Randomness -Version 0.4.1
<PackageReference Include="NCode.Randomness" Version="0.4.1" />
<PackageVersion Include="NCode.Randomness" Version="0.4.1" />
<PackageReference Include="NCode.Randomness" />
paket add NCode.Randomness --version 0.4.1
#r "nuget: NCode.Randomness, 0.4.1"
#:package NCode.Randomness@0.4.1
#addin nuget:?package=NCode.Randomness&version=0.4.1
#tool nuget:?package=NCode.Randomness&version=0.4.1
NCode.Randomness
Cryptographically secure random numbers for .NET, strengthened by public randomness beacons such as CURBy, and reproducible draws that anyone can check against a beacon pulse.
ISecureRandom: an NIST SP 800-90A HMAC_DRBG (HMAC-SHA-512) per processor, seeded and reseeded from the operating system's CSPRNG, with every verified beacon pulse mixed in as additional input. Its output is at least as strong as the operating system's generator whatever a beacon publishes, and a call never waits on the network.- Typed values over any source: unbiased integers in any range for every integer type from
bytetoUInt128, doubles, singles, booleans, version 4 GUIDs, shuffles, choices, strings from an alphabet, and aSystem.Randomadapter. - Beacons in the background: one loop per registered beacon, with timeouts, back-off and jitter;
Continuous,InitializeOnly(start online, then run offline) andOfflinemodes; rollback, equivocation and staleness checks; a health check that reports an outage asDegraded; metrics throughIMeterFactory. - Reproducible draws:
IVerifiableRandomFactoryderives a deterministic stream,ncode-randomness-draw/1, from one verified pulse and a context label, for raffles, audits and sortition. It is deliberately not anISecureRandom. RandomnessHost: the same generator and beacons without dependency injection, for console tools and libraries: build it withRandomnessHost.CreateBuilder()andBuildAsync, and dispose it to stop the beacons.SystemRandomSource.Instance: the operating system's generator behind the same API, with no beacon and nothing to dispose.
builder.Services
.AddRandomness(builder.Configuration.GetSection(RandomnessOptions.SectionName))
.AddCurbyBeacon(); // from NCode.Randomness.Curby
public sealed class TokenService(ISecureRandom random)
{
public string NewRecoveryCode() => random.GetString("ABCDEFGHJKLMNPQRSTUVWXYZ23456789", 16);
public int RollDie() => random.NextInteger(1, 7);
}
For a key, call Fill with a stackalloc or pinned span and clear it with CryptographicOperations.ZeroMemory after
use, rather than keeping it in the byte[] that GetBytes returns. A key that outlives one method belongs in a pinned
buffer that is zeroed on dispose, such as one from NCode.Buffers'
BufferFactory.Rent(32, isSensitive: true, out Span<byte> key).
Beacon adapters implement IRandomnessBeacon and register with AddBeacon<TBeacon>(). The repository's README and
docs/ folder hold the full guide, the draw specification and the decision records.
| 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.DependencyInjection (>= 11.0.0)
- Microsoft.Extensions.Diagnostics (>= 11.0.0)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 11.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 11.0.0)
- Microsoft.Extensions.Logging (>= 11.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 11.0.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on NCode.Randomness:
| Package | Downloads |
|---|---|
|
NCode.Randomness.Curby
The CURBy (CU Randomness Beacon, University of Colorado Boulder) adapter for NCode.Randomness: fetches pulses of the CURBy-RNG Twine chain and rounds of the CURBy-Q chain, or takes their saved documents offline, and verifies their content identifiers, RS256 signatures and precommitments against pinned chains before any byte is used. |
|
|
NCode.Randomness.Drand
The drand adapter for NCode.Randomness: fetches rounds of the League of Entropy's quicknet chain, or takes saved round documents offline, and verifies their BLS12-381 threshold signatures against the pinned group public key before any byte is used. |
|
|
NCode.Randomness.Nist
The NIST Randomness Beacon 2.0 adapter for NCode.Randomness: fetches pulses of the NIST beacon's chain, or takes saved pulse and certificate documents offline, and verifies their RSA signatures against pinned certificates, their output values, and their hash chain and precommitment to the previous pulse before any byte is used. |
GitHub repositories
This package is not used by any popular GitHub repositories.
See the changelog: https://github.com/NCodeGroup/Randomness/blob/HEAD/CHANGELOG.md