RngNumberGenerator 1.0.2

dotnet add package RngNumberGenerator --version 1.0.2
                    
NuGet\Install-Package RngNumberGenerator -Version 1.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RngNumberGenerator" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RngNumberGenerator" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="RngNumberGenerator" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RngNumberGenerator --version 1.0.2
                    
#r "nuget: RngNumberGenerator, 1.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RngNumberGenerator@1.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RngNumberGenerator&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=RngNumberGenerator&version=1.0.2
                    
Install as a Cake Tool

Deterministic Hash-Based Random Utilities

A lightweight C# utility for generating deterministic pseudo-random values from hexadecimal hashes. Designed for scenarios requiring reproducible randomness such as gaming logic, provably-fair systems, shuffling, and outcome generation.

Features

  • Deterministic random int and long generation from hex strings
  • Outcome range validation to ensure symmetric distribution
  • SHA1-based hash rotation with nonce
  • Deterministic array shuffling (Fisher–Yates)
  • No mutation of input collections
  • Pure static utility methods

How It Works

The library converts a hexadecimal string into a numeric value and maps it proportionally into the range:

0 .. (n - 1)

Distribution symmetry is preserved by validating that the hex string has sufficient entropy for the requested number of outcomes.

API

ValidateHexLength(string hex, long n)

Ensures the provided hex string contains enough entropy to fairly generate n outcomes.

Throws:

  • ArgumentOutOfRangeException if n ⇐ 1
  • OverflowException if n exceeds supported range
  • ArgumentException if hex length is insufficient
int Rand(string hex, int n)

Returns a deterministic random integer in:

0 .. (n - 1)

Uses proportional scaling from the hex value.

long RandLong(string hex, long n)

Same as Rand, but supports long ranges.

string RotateHash(string hash, int nonce)

Generates a new SHA1-based hash using: SHA1(hash + nonce) Useful for generating sequential deterministic randomness.

IList<T> Shuffle<T>(IList<T> arr, string hash)

Returns a new shuffled copy of the array using a deterministic Fisher–Yates algorithm. Seed is derived from first 8 hex characters. Original collection is not mutated.

Example

string hash = "a3f5c9e1b7d4";

// Random number between 0 and 9
int result = Rand(hash, 10);

// Random long between 0 and 999
long longResult = RandLong(hash, 1000);

// Rotate hash
string nextHash = RotateHash(hash, 1);

// Shuffle
var numbers = new[] { 1, 2, 3, 4, 5 };
var shuffled = Shuffle(numbers, hash);

Use Cases

  • Provably fair gaming systems
  • Deterministic simulations
  • Reproducible shuffling
  • Blockchain or hash-seeded logic
  • Server/client verifiable randomness
Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 84 2/24/2026
1.0.1 69 2/16/2026