RandomExtension 1.0.0

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

// Install RandomExtension as a Cake Tool
#tool nuget:?package=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
        }
    }
}
Product Compatible and additional computed target framework versions.
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

This package has 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.0 1,259 12/29/2017

Add all type of numeric.