Tedd.MoreRandom 1.0.0

.NET Standard 1.3
There is a newer version of this package available.
See the version list below for details.
dotnet add package Tedd.MoreRandom --version 1.0.0
NuGet\Install-Package Tedd.MoreRandom -Version 1.0.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="Tedd.MoreRandom" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tedd.MoreRandom --version 1.0.0
#r "nuget: Tedd.MoreRandom, 1.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Tedd.MoreRandom as a Cake Addin
#addin nuget:?package=Tedd.MoreRandom&version=1.0.0

// Install Tedd.MoreRandom as a Cake Tool
#tool nuget:?package=Tedd.MoreRandom&version=1.0.0


Drop-in replacement for System.Random based on RandomNumberGenerator.


Works exactly like System.Random, except you may want to dispose of it when you are done. (If you don't dispose of it, the destructor will do it for you upon garbage collect.)

<pre><code>var rnd = new Tedd.MoreRandom.Random(); var dice = rnd.Next(1, 7); // A random number between 1 and 6 inclusive rnd.Dispose();</code></pre> <pre><code>using (var rnd = new Tedd.MoreRandom.Random()) { var percent = rnd.NextDouble() * 100; Console.WriteLine($"You are {percent}% done, please wait..."); }</code></pre>

Note that it is recommended to create a shared Random object, and in case of multiple threads use synchronized access to generate random data.

<pre><code>public static class Main: IDisposable { public static Tedd.MoreRandom.Random Rnd = new Tedd.MoreRandom.Random();

public static void Start() {
	int dice;
	lock (Rnd)
		dice = Rnd.Next(1, 7); // A random number between 1 and 6 inclusive


Thread safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


System.Random is based on so called "pseudorandom" algorithm. This means that given a seed (default this is number of milliseconds since computer was started) math is used to generate seemingly random numbers. Given the same seed, a sequence of random numbers will look the same every time. For most cases this is fine, but in some cases you need more random data. One such case is cryptography, where a pseudorandom generator such as System.Random would generate a predictable sequence of numbers.

System.Security.Cryptography.RandomNumberGenerator provides "cryptography grade random" numbers. These numbers are a bit more random as they are provided by the operating system, which has methods of collecting random data.

RandomNumberGenerator gives you a bunch of random bytes. It's up to you to convert to a number and size for whatever purpose. System.Random however has a simple interface, for example rnd.Next(10).

This is where MoreRandom comes in. Tedd.MoreRandom.Random mimics System.Random and is a drop-in replacement. You get the power of RandomNumberGenerator with the ease of System.Random.


Created using .Net Standard 1.3.

Unit testing

xUnit in .Net Core with near 100% code coverage. Boundary checks as well as average check on vast number of samples.

System.Security.Cryptography.RandomNumberGenerator on MSDN

Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard1.3 netstandard1.4 netstandard1.5 netstandard1.6 netstandard2.0 netstandard2.1
.NET Framework net46 net461 net462 net463 net47 net471 net472 net48
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen30 tizen40 tizen60
Universal Windows Platform uap uap10.0
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
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.1 3,342 11/23/2017
1.0.0 3,573 11/19/2017

Initial release.