Cayd.Random.Extensions
1.0.4
dotnet add package Cayd.Random.Extensions --version 1.0.4
NuGet\Install-Package Cayd.Random.Extensions -Version 1.0.4
<PackageReference Include="Cayd.Random.Extensions" Version="1.0.4" />
<PackageVersion Include="Cayd.Random.Extensions" Version="1.0.4" />
<PackageReference Include="Cayd.Random.Extensions" />
paket add Cayd.Random.Extensions --version 1.0.4
#r "nuget: Cayd.Random.Extensions, 1.0.4"
#addin nuget:?package=Cayd.Random.Extensions&version=1.0.4
#tool nuget:?package=Cayd.Random.Extensions&version=1.0.4
About
This package extends the System.Random
class for more random generators, such as generating random values for all numeric types with or without a range (sbyte
, byte
, short
, ushort
, int
, uint
, long
, ulong
, float
, double
, decimal
) and generating a boolean value with or without a probability.
How to Use
After installing the package and adding Cayd.Random.Extensions
namespace to your code, you can start using the extensions method of the package.
A few example of how to use the library:
using Cayd.Random.Extensions
Random rnd = new Random();
bool rndBool = rnd.NextBool(0.7);
decimal rndDecimal rnd.NextDecimal(100m, 1000000000m);
uint rndUint = rnd.NextUInt(100u, uint.MaxValue);
ulong rndUlong = rnd.NextULong(5000000uL);
// or for .Net 6 or higher, the static 'Shared' property can be used
bool rndBool = Random.Shared.NextBool(0.7);
decimal rndDecimal Random.Shared.NextDecimal(100m, 1000000000m);
uint rndUint = Random.Shared.NextUInt(100u, uint.MaxValue);
ulong rndUlong = Random.Shared.NextULong(5000000uL);
Extensions
- Parameterless methods returns a random value between the type's min and max values.
- Methods with one parameter return a random value between 0 and a specified max value.
- Methods with two parameters return a random value within a specified range.
Type | (No Parameter) | Only Max | Min and Max |
---|---|---|---|
sbyte |
NextSByte() | NextSByte(maxValue) | NextSByte(minValue, maxValue) |
byte |
NextByte() | NextByte(maxValue) | NextByte(minValue, maxValue) |
short |
NextShort() | NextShort(maxValue) | NextShort(minValue, maxValue) |
ushort |
NextUShort() | NextUShort(maxValue) | NextUShort(minValue, maxValue) |
int |
NextInt() | NextInt(maxValue) | NextInt(minValue, maxValue) |
uint |
NextUInt() | NextUInt(maxValue) | NextUInt(minValue, maxValue) |
long |
NextLong() | NextLong(maxValue) | NextLong(minValue, maxValue) |
ulong |
NextULong() | NextULong(maxValue) | NextULong(minValue, maxValue) |
float |
NextFloat() | NextFloat(maxValue) | NextFloat(minValue, maxValue) |
double |
NextDoubleLimits() | NextDouble(maxValue) | NextDouble(minValue, maxValue) |
decimal |
NextDecimal() | NextDecimal(maxValue) | NextDecimal(minValue, maxValue) |
For boolean:
- The parameterless method returns a random boolean value with a 50% chance of being
true
. - The method with one parameter returns a random boolean value with a specified chance of being
true
.
Type | (No Parameter) | Probability |
---|---|---|
bool |
NextBool() | NextBool(probability) |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. 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 is compatible. 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. |
-
.NETStandard 2.0
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Cayd.Random.Extensions:
Package | Downloads |
---|---|
Cayd.Test.Generators
A utility library for tests that simplifies the generation of variables, classes and collections |
GitHub repositories
This package is not used by any popular GitHub repositories.
Update package info