dotnet add package Fortuna --version 1.0.1
NuGet\Install-Package Fortuna -Version 1.0.1
<PackageReference Include="Fortuna" Version="1.0.1" />
paket add Fortuna --version 1.0.1
#r "nuget: Fortuna, 1.0.1"
// Install Fortuna as a Cake Addin #addin nuget:?package=Fortuna&version=1.0.1 // Install Fortuna as a Cake Tool #tool nuget:?package=Fortuna&version=1.0.1
This is an implementation of the Fortuna PRNG algorithm for .NET. It has been built on NETStandard 1.3, and so is compatible with .NET Framework 4.6 as well as .NET Core 1.0 or higher (on Mac, Linux and Windows).
What is Fortuna?
Fortuna is a cryptographically secure pseudo-random number generator. You can read the published specification here.
Fortuna is a family of secure PRNGs; its design leaves some choices open to implementors. It is composed of the following pieces:
- The generator itself, which once seeded will produce an indefinite quantity of pseudo-random data.
- The entropy accumulator, which collects genuinely random data from various sources and uses it to reseed the generator when enough new randomness has arrived.
- The seed file, which stores enough state to enable the computer to start generating random numbers as soon as it has booted.
You can download the package on nuget.org.
It is recommended that you use one of the provided factory methods to construct the provider:
var rng = PRNGFortunaProviderFactory.Create();
There is also an asynchronous override provided:
var tokenSource = new CancellationTokenSource(); var token = tokenSource.Token; var rng = await PRNGFortunaProviderFactory.CreateAsync(token);
The latter will allow you to create the PRNG asynchronously - this may be preferable, as depending on external conditions, it may take a while before there is sufficient random data accumulated before the PRNG is ready for use.
Regardless of the method used to construct the PRNG, you can request random data via the following method:
var data = new byte; var randomData = prng.GetBytes(data);
If you are only interested in selecting a random integer greater than or equal to 0, you can use the following extension method:
int randNumber = prng.RandomNumber(10);
This will return a number in the range of [0, 10)
Sources of Entropy
The architecture of this particular implementation explicitly allows for adding new sources of entropy. The following sources are provided out of the box:
- .NET CryptoServiceProvider
- Environment Uptime
- Garbage Collector Statistics
- Current Process Statistics
- System Time
New providers can be plugged in as needed, up to a maximum of 255 total.
This implementation uses a basic event-based scheduler to periodically sample entropy providers for new data.
Entropy providers have the latitude to include up to as much as 32 bytes of entropy, and can dictate the sample period.
|Product||Versions 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-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed.|
|.NET Core||netcoreapp1.0 was computed. netcoreapp1.1 was computed. netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed.|
|.NET Standard||netstandard1.3 is compatible. netstandard1.4 was computed. netstandard1.5 was computed. netstandard1.6 was computed. netstandard2.0 was computed. netstandard2.1 was computed.|
|.NET Framework||net46 was computed. 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||tizen30 was computed. tizen40 was computed. tizen60 was computed.|
|Universal Windows Platform||uap was computed. uap10.0 was computed.|
|Xamarin.iOS||xamarinios was computed.|
|Xamarin.Mac||xamarinmac was computed.|
|Xamarin.TVOS||xamarintvos was computed.|
|Xamarin.WatchOS||xamarinwatchos was computed.|
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.