RandomExtension 1.0.0
A light weight C# extension of random method for all numeric type.
Install-Package RandomExtension -Version 1.0.0
dotnet add package RandomExtension --version 1.0.0
<PackageReference Include="RandomExtension" Version="1.0.0" />
paket add RandomExtension --version 1.0.0
CSharp-RandomExtension
A light weight C# extension of random method for all numeric type.
Language and Framework
C# .NET 4.5 above
How to Use
Install
Chose one in the following:
- Search nuget for "RandomExtension"
- Run the following command in the Package Manager Console:
PM> Install-Package RandomExtension
- Download RandomExtension.dll and add referance to project.
- Download RandomExtension.cs file and add it into project.(C# 6 above)
NameSpace
using System.RandomExtension;
Use Extension
All extension method can be use like default method of System.Random, for example:
Random rnd = new Random();
//Random rnd = new Random(seed); //with seed
int randomInt = rnd.Next();
ulong randomULong = rnd.NextULong();
sbyte randomSByte = rnd.NextSByte(50);
decimal randomDecimal = rnd.NextDecimal(-3.5m, 8.55m);
For more detail, see document in Document of All Method section on the project site.
List of Extension Method of System.Random
- public double NextDouble(double minValue, double maxValue)
- public float NextFloat()
- public float NextFloat(float minValue, float maxValue)
- public decimal NextDecimal()
- public decimal NextDecimal(decimal minValue, decimal maxValue)
- public byte NextByte()
- public byte NextByte(byte maxValue
- public byte NextByte(byte minValue, byte maxValue)
- public sbyte NextSByte()
- public sbyte NextSByte(sbyte maxValue)
- public sbyte NextSByte(sbyte minValue, sbyte maxValue)
- public short NextShort()](#nextshort)
- public short NextShort(short maxValue)
- public short NextShort(short minValue, short maxValue)
- public ushort NextUShort()
- public ushort NextUShort(ushort maxValue)
- public ushort NextUShort(ushort minValue, ushort maxValue)
- public uint NextUInt()
- public uint NextUInt(uint maxValue)
- public uint NextUInt(uint minValue, uint maxValue)
- public long NextLong()
- public long NextLong(long maxValue)
- public long NextLong(long minValue, long maxValue)
- public ulong NextULong()
- public ulong NextULong(ulong maxValue)
- public ulong NextULong(ulong minValue, ulong maxValue)
Custom Random
For custom random algorithm or behavior, any class that inherit from System.Random can use these extension method too, and for those custom random class that override default random method(Next(), NextDouble(), NextBytes()), the behavior for method in this extension will also change, for example:
using System;
using System.RandomExtension;
namespace RandomExtensionExample
{
public class MyRandom : System.Random
{
public MyRandom() : base() { }
public MyRandom(int Seed) : base(Seed) { }
public override int Next(int minValue, int maxValue)
{
return 100;
}
}
public class Example
{
public static void Main()
{
MyRandom() rnd = new MyRandom();
//MyRandom rnd = new MyRandom(seed); //with seed
byte b = rnd.NextByte(0, 50); //100
}
}
}
CSharp-RandomExtension
A light weight C# extension of random method for all numeric type.
Language and Framework
C# .NET 4.5 above
How to Use
Install
Chose one in the following:
- Search nuget for "RandomExtension"
- Run the following command in the Package Manager Console:
PM> Install-Package RandomExtension
- Download RandomExtension.dll and add referance to project.
- Download RandomExtension.cs file and add it into project.(C# 6 above)
NameSpace
using System.RandomExtension;
Use Extension
All extension method can be use like default method of System.Random, for example:
Random rnd = new Random();
//Random rnd = new Random(seed); //with seed
int randomInt = rnd.Next();
ulong randomULong = rnd.NextULong();
sbyte randomSByte = rnd.NextSByte(50);
decimal randomDecimal = rnd.NextDecimal(-3.5m, 8.55m);
For more detail, see document in Document of All Method section on the project site.
List of Extension Method of System.Random
- public double NextDouble(double minValue, double maxValue)
- public float NextFloat()
- public float NextFloat(float minValue, float maxValue)
- public decimal NextDecimal()
- public decimal NextDecimal(decimal minValue, decimal maxValue)
- public byte NextByte()
- public byte NextByte(byte maxValue
- public byte NextByte(byte minValue, byte maxValue)
- public sbyte NextSByte()
- public sbyte NextSByte(sbyte maxValue)
- public sbyte NextSByte(sbyte minValue, sbyte maxValue)
- public short NextShort()](#nextshort)
- public short NextShort(short maxValue)
- public short NextShort(short minValue, short maxValue)
- public ushort NextUShort()
- public ushort NextUShort(ushort maxValue)
- public ushort NextUShort(ushort minValue, ushort maxValue)
- public uint NextUInt()
- public uint NextUInt(uint maxValue)
- public uint NextUInt(uint minValue, uint maxValue)
- public long NextLong()
- public long NextLong(long maxValue)
- public long NextLong(long minValue, long maxValue)
- public ulong NextULong()
- public ulong NextULong(ulong maxValue)
- public ulong NextULong(ulong minValue, ulong maxValue)
Custom Random
For custom random algorithm or behavior, any class that inherit from System.Random can use these extension method too, and for those custom random class that override default random method(Next(), NextDouble(), NextBytes()), the behavior for method in this extension will also change, for example:
using System;
using System.RandomExtension;
namespace RandomExtensionExample
{
public class MyRandom : System.Random
{
public MyRandom() : base() { }
public MyRandom(int Seed) : base(Seed) { }
public override int Next(int minValue, int maxValue)
{
return 100;
}
}
public class Example
{
public static void Main()
{
MyRandom() rnd = new MyRandom();
//MyRandom rnd = new MyRandom(seed); //with seed
byte b = rnd.NextByte(0, 50); //100
}
}
}
Release Notes
Add all type of numeric.
Dependencies
This package has no dependencies.
GitHub Usage
This package is not used by any popular GitHub repositories.
Version History
Version | Downloads | Last updated | ||
---|---|---|---|---|
1.0.0 | 359 | 12/29/2017 |