Tedd.RandomUtils 1.0.0

Random Extension Methods for SByte, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64, short, int, long. This packet replaced Tedd.MoreRandom and Tedd.RandomExtensions.

There is a newer version of this package available.
See the version list below for details.
Install-Package Tedd.RandomUtils -Version 1.0.0
dotnet add package Tedd.RandomUtils --version 1.0.0
<PackageReference Include="Tedd.RandomUtils" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tedd.RandomUtils --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Tedd.RandomUtils, 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.RandomUtils as a Cake Addin
#addin nuget:?package=Tedd.RandomUtils&version=1.0.0

// Install Tedd.RandomUtils as a Cake Tool
#tool nuget:?package=Tedd.RandomUtils&version=1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Extension methods

Extension methods for System.Random that adds support for more datatypes.
NextSByte(), NextByte(), NextInt16(), NextUInt16(), NextIn32(), NextUInt32(), NextInt64(), NextUInt64() and NextFloat().

Note on vanilla System.Random vs this library

Standard System.Random.Next() returns a positive integer, while all this library return full range of values for given datatype.
Standard System.Random.Next(from, to) has "exclusive to" value, meaning it only returns 31 random bits in the 32-bit integer. This library returns random for all 32 and 64 bits on NextInt32(), NextUInt32, NextInt64() and NextUInt64() respectively.

Examples

Random by type

var rnd = new Random();

sbyte val1 = rnd.NextSByte();
byte val1 = rnd.NextByte();
short val2 = rnd.NextInt16();
ushort val3 = rnd.NextUInt16();
int val4 = rnd.NextInt32();
uint val5 = rnd.NextUInt32();
long val6 = rnd.NextInt64();
ulong val7 = rnd.NextUInt64();
float val8 = rnd.NextFloat();

Thread safe random

Thread safe random without locking.

sbyte val1 = ConcurrentRandom.NextSByte();
byte val1 = ConcurrentRandom.NextByte();
short val2 = ConcurrentRandom.NextInt16();
ushort val3 = ConcurrentRandom.NextUInt16();
int val4 = ConcurrentRandom.NextInt32();
uint val5 = ConcurrentRandom.NextUInt32();
long val6 = ConcurrentRandom.NextInt64();
ulong val7 = ConcurrentRandom.NextUInt64();
float val8 = ConcurrentRandom.NextFloat();

Crypto strength random

using rnd = new CryptoRandom();

sbyte val1 = rnd.NextSByte();
byte val1 = rnd.NextByte();
short val2 = rnd.NextInt16();
ushort val3 = rnd.NextUInt16();
int val4 = rnd.NextInt32();
uint val5 = rnd.NextUInt32();
long val6 = rnd.NextInt64();
ulong val7 = rnd.NextUInt64();
float val8 = rnd.NextFloat();

Extension methods

Extension methods for System.Random that adds support for more datatypes.
NextSByte(), NextByte(), NextInt16(), NextUInt16(), NextIn32(), NextUInt32(), NextInt64(), NextUInt64() and NextFloat().

Note on vanilla System.Random vs this library

Standard System.Random.Next() returns a positive integer, while all this library return full range of values for given datatype.
Standard System.Random.Next(from, to) has "exclusive to" value, meaning it only returns 31 random bits in the 32-bit integer. This library returns random for all 32 and 64 bits on NextInt32(), NextUInt32, NextInt64() and NextUInt64() respectively.

Examples

Random by type

var rnd = new Random();

sbyte val1 = rnd.NextSByte();
byte val1 = rnd.NextByte();
short val2 = rnd.NextInt16();
ushort val3 = rnd.NextUInt16();
int val4 = rnd.NextInt32();
uint val5 = rnd.NextUInt32();
long val6 = rnd.NextInt64();
ulong val7 = rnd.NextUInt64();
float val8 = rnd.NextFloat();

Thread safe random

Thread safe random without locking.

sbyte val1 = ConcurrentRandom.NextSByte();
byte val1 = ConcurrentRandom.NextByte();
short val2 = ConcurrentRandom.NextInt16();
ushort val3 = ConcurrentRandom.NextUInt16();
int val4 = ConcurrentRandom.NextInt32();
uint val5 = ConcurrentRandom.NextUInt32();
long val6 = ConcurrentRandom.NextInt64();
ulong val7 = ConcurrentRandom.NextUInt64();
float val8 = ConcurrentRandom.NextFloat();

Crypto strength random

using rnd = new CryptoRandom();

sbyte val1 = rnd.NextSByte();
byte val1 = rnd.NextByte();
short val2 = rnd.NextInt16();
ushort val3 = rnd.NextUInt16();
int val4 = rnd.NextInt32();
uint val5 = rnd.NextUInt32();
long val6 = rnd.NextInt64();
ulong val7 = rnd.NextUInt64();
float val8 = rnd.NextFloat();

  • .NETCoreApp 2.0

    • No dependencies.
  • .NETCoreApp 2.1

    • No dependencies.
  • .NETCoreApp 3.0

    • No dependencies.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.6.1

    • No dependencies.
  • .NETStandard 2.1

    • 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 History

Version Downloads Last updated
1.0.6 435 1/26/2021
1.0.5 281 12/18/2020
1.0.4 591 5/1/2020
1.0.3 227 3/25/2020
1.0.2 176 2/1/2020
1.0.1 198 12/21/2019
1.0.0 204 12/19/2019
Show less