StrongRandom 2.1.0

dotnet add package StrongRandom --version 2.1.0
                    
NuGet\Install-Package StrongRandom -Version 2.1.0
                    
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="StrongRandom" Version="2.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="StrongRandom" Version="2.1.0" />
                    
Directory.Packages.props
<PackageReference Include="StrongRandom" />
                    
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 StrongRandom --version 2.1.0
                    
#r "nuget: StrongRandom, 2.1.0"
                    
#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 StrongRandom@2.1.0
                    
#: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=StrongRandom&version=2.1.0
                    
Install as a Cake Addin
#tool nuget:?package=StrongRandom&version=2.1.0
                    
Install as a Cake Tool

StrongRandom

CI Quality Gate Status Coverage NuGet version NuGet downloads License: MIT Buy Me A Coffee

System.Random drop-in backed by a Cryptographically-Secure Pseudo-Random Number Generator (CSPRNG). Everywhere you use System.Random, StrongRandom can be used instead. Also ships extension methods that add NextBool, NextByte, NextChar, NextFloat, NextNormal and more to any Random instance.

Security note: NextBytes() is a direct call to the underlying CSPRNG and is safe. Integer-returning methods (Next, Next(max), Next(min, max)) and NextDouble() involve a transformation step that introduces a slight bias — do not rely on these for security-critical decisions such as key generation. Use NextBytes() for raw entropy.

Installation

dotnet add package StrongRandom

Quick start

using Extensions.Standard.Randomization;

// Drop-in: assign to a System.Random variable
Random rng = new StrongRandom();

int dice   = rng.Next(1, 7);          // 1–6
double d   = rng.NextDouble();        // [0, 1)
byte[] key = new byte[32];
rng.NextBytes(key);                   // CSPRNG-safe raw bytes

Extension methods (Utilities)

All extensions target System.Random, so they work with StrongRandom, plain new Random(), or a mock.

Method Signature Description
NextByte (short upperLimit = 256) Random byte in [0, upperLimit)
NextBool () true or false with equal probability
NextChar (char lower = ' ', char upper = '\x7F') Random character in printable ASCII range
NextChar (string chooseFrom) Random character from a specific set
NextLowercaseLetter () Random letter az
NextUppercaseLetter () Random letter AZ
NextLetter () Random letter az or AZ
NextAlphanumeric () Random digit, uppercase, or lowercase letter
NextFloat () Random float in [0, 1)
NextFloat (float min, float max) Random float in [min, max)
NextDouble (double max) Random double in [0, max)
NextDouble (double min, double max) Random double in [min, max)
NextNormal (double mean, double sd = 1) Normally distributed value (Box-Muller)
var rng = new StrongRandom();

bool coinFlip       = rng.NextBool();
byte b              = rng.NextByte();
char letter         = rng.NextLetter();
char alphanumeric   = rng.NextAlphanumeric();
float f             = rng.NextFloat(0f, 1f);
double normal       = rng.NextNormal(mean: 0, sd: 1);
char fromSet        = rng.NextChar("AEIOU");

Customising the provider

StrongRandom depends on IRandomProvider for its byte source. The default is BufferedRandomProvider(44), which pre-fetches 44 bytes per CSPRNG call to reduce overhead.

// Larger buffer — fewer round-trips to the CSPRNG
var rng = new StrongRandom(new BufferedRandomProvider(256));

// Custom provider (e.g. for testing)
public class MyProvider : IRandomProvider
{
    public void GetBytes(byte[] input) { /* ... */ }
}
var testRng = new StrongRandom(new MyProvider());

API

StrongRandom

Inherits from System.Random. All Random members work as expected; randomness comes from the CSPRNG provider.

Member Notes
StrongRandom(IRandomProvider? provider = null) null uses BufferedRandomProvider(44)
Next() CSPRNG-backed
Next(int maxValue) CSPRNG-backed
Next(int minValue, int maxValue) CSPRNG-backed
NextDouble() CSPRNG-backed
NextBytes(byte[] buffer) Direct CSPRNG fill — unbiased

BufferedRandomProvider

Member Notes
BufferedRandomProvider(int bufferSize) Pre-fetches bufferSize bytes per CSPRNG call
GetBytes(byte[] input) Fills input from the buffer, refreshing as needed

IRandomProvider

public interface IRandomProvider
{
    void GetBytes(byte[] input);
}

License

MIT — see LICENSE.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on StrongRandom:

Package Downloads
Sequence

The package is intended to help generate various sequences, random and with rules. Provided is Sequence class, that given min, max and step. Calculate, without enumerating, sum, length, Variance, Standard Deviation etc.. Can enumerate lazily all elements. Also, extension methods to System.Random added.

SimpleML.GeneticAlgorithm

Simple Genetic Algorithm implementation

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.1.0 26 6/21/2026
2.0.0 4,858 1/21/2018
1.2.0 1,885 6/23/2017
1.1.1 1,291 6/21/2017
1.1.0 1,649 6/21/2017
1.0.1 1,411 6/17/2017
1.0.0 1,411 6/17/2017