PutridParrot.Randomizer 1.0.8-alpha

This is a prerelease version of PutridParrot.Randomizer.
dotnet add package PutridParrot.Randomizer --version 1.0.8-alpha
NuGet\Install-Package PutridParrot.Randomizer -Version 1.0.8-alpha
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="PutridParrot.Randomizer" Version="1.0.8-alpha" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PutridParrot.Randomizer --version 1.0.8-alpha
#r "nuget: PutridParrot.Randomizer, 1.0.8-alpha"
#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.
// Install PutridParrot.Randomizer as a Cake Addin
#addin nuget:?package=PutridParrot.Randomizer&version=1.0.8-alpha&prerelease

// Install PutridParrot.Randomizer as a Cake Tool
#tool nuget:?package=PutridParrot.Randomizer&version=1.0.8-alpha&prerelease

PutridParrot.Randomizer

Build PutridParrot.Randomizer NuGet version (PutridParrot.Randomizer) GitHub license GitHub Releases GitHub Issues

Extended functionality for Random value generation, includes Concurrent implementation and non-concurrent versions as well as Crypto versions.

The main aim of this package was three-fold - firstly to create a random number generator interface for mocking out random number generation, secondly to add a thread-safe implementation and thirdly to add extensions to give more functionality to the random number generator.

The core IRandomizer implementations supply the low-level random number generation code, whilst the extension methods supply additions to these, such as generated random strings, dates, etc.

Usage

Install the latest package from nuget, for example by running

dotnet add package PutridParrot.Randomizer --version 1.0.6-alpha

In usages we simply use something like the following

using PutridParrot.Randomizer;

var randomizer = new PseudoRandomizer();
var value = randomizer.NextDate(DateTime.Now.AddDays(30));

In the example above we're using the NextDate method to give us a random date between DateTime.Now and up to, but less than, 30 days in the future.

API

This is just an overview of the API, in most cases we'll have versions of NextXXX where XXX will be a Long, Double, Bool or whatever. In some cases an API will have a version with no arguments, this defaults to [0, MAX_VALUE(type)[. In other words from 0 through to int.MaxValue or whatever the type's max value is. The second type of method generally takes a single argument to replace the max value and then the third version will take min and max values.

NextInt

Gets a random integer

var value = randomizer.NextInt();

NextByte

Gets a random byte

var value = randomizer.NextByte();

NextDouble

Gets a random double

var value = randomizer.NextDouble();

NextLong

Gets a random long

var value = randomizer.NextLong();

NextBool

Gets a random boolean

var value = randomizer.NextBool();

NextDateTime

Gets a random DateTime

var value = randomizer.NextDateTime();

NextDate

Gets a random DateTime where the .Date is passsed back

var value = randomizer.NextDate();

NextItem

Get a random item from a list with

var value = randomizer.NextItem(new [] { 1, 2, 3, 4, 5 });

NextItem

Get a random enum value from a supplied Enum type

var value = randomizer.NextEnum<SomeEnum>();

Shuffle

Shuffle a supplied IList of items.

Note: Whilst this returns the original IList, the IList is mutated, if you want to keep the original IList in order, clone the list before passing it into Shuffle.

var value = randomizer.Shuffle(new [] { 1, 2, 3, 4, 5 });

NextGaussian

var value = randomizer.NextGaussian();

NextString

Gets a random string of the given length (in the example below the length is 10) and generate the string from the character set supplied (in this example it's all alpha characters only)

var value = randomizer.NextString(10, "abcdefghijklmnopqrstuvwxyz");

NextList

Gets a random IList of type T of the given length (in the example below the length is 10). The random IList is generated from the available values in the supplied list (in this example the random list will be 10 items taken from [1, 5] values)

var value = randomizer.NextList(10, new [] { 1, 2, 3, 4, 5 });
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

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.8-alpha 96 10/10/2022
1.0.7-alpha 104 9/24/2022
1.0.6-alpha 95 9/23/2022
1.0.5-alpha 118 1/18/2022
1.0.4-alpha 113 1/18/2022
1.0.3-alpha 114 1/18/2022
1.0.2-alpha 118 12/13/2021
1.0.0-alpha 282 8/14/2020