Generates a random double number between the specified numbers from a seeded random - CSharp System

CSharp examples for System:Random

Description

Generates a random double number between the specified numbers from a seeded random

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//  w w w .ja  v a 2 s  .  co m

public class Main{
        /// <summary>Generates a random double number between the specified numbers from a seeded random</summary>
        /// <param name="min">The minimum number that the random number can be</param>
        /// <param name="max">The maximum number that the random number can be</param>
        /// <returns>A random double number between the spesified numbers based on the seeded random generator used</returns>
        public static double GenerateRandom(this Random seedRand, double min, double max)
        {
            return min + (float)(seedRand.NextDouble() * (max - min));
        }
        /// <summary>Generates a random double number between the spesified numbers</summary>
        /// <param name="min">The minimum number that the random number can be</param>
        /// <param name="max">The maximum number that the random number can be</param>
        /// <returns>A random double number between the spesified numbers</returns>
        public static double GenerateRandom(double min, double max)
        {
            return min + (float)(random.NextDouble() * (max - min));
        }
        /// <summary>Generates a random floating point between the two spesified numbers from a seeded random</summary>
        /// <param name="seedRand">The seeded random number used to generate the random floating point</param>
        /// <param name="min">The minimum number that the random number can be</param>
        /// <param name="max">The maximum number that the random number can be</param>
        /// <returns>A random floating point number between the spesified numbers based on the seeded random generator used</returns>
        public static float GenerateRandom(this Random seedRand, float min, float max)
        {
            return min + (float)(seedRand.NextDouble() * (max - min));
        }
        /// <summary>Generates a random floating point number between the sepeified numbers</summary>
        /// <param name="min">The minimum number that the random number can be</param>
        /// <param name="max">The maximum number that the random number can be</param>
        /// <returns>A random floating point number between the spesified numbers</returns>
        public static float GenerateRandom(float min, float max)
        {
            return min + (float)(random.NextDouble() * (max - min));
        }
        /// <summary>Generates a random Long integer between the two spesified numbers</summary>
        /// <param name="min">The minimum that the number can be</param>
        /// <param name="max">The maximum that the number can be</param>
        /// <returns>A random long number between the two spesified numbers</returns>
        public static long GenerateRandom(long min, long max)
        {
            throw new NotImplementedException();
            //long rand = GenerateRandomLong();

            //return rand;
        }
        /// <summary>Generates a random integer between the two spesified numbers from a seeded random</summary>
        /// <param name="seedRand">The seeded random number used to generate the random integer</param>
        /// <param name="min">The minimum that the number can be</param>
        /// <param name="max">The maximum that the number can be</param>
        /// <returns>A random number between the two spesified numbers based on the seeded random generator used</returns>
        public static int GenerateRandom(this Random seedRand, int min, int max)
        {
            return seedRand.Next(min, max);
        }
        /// <summary>Generates a random integer between the two spesified numbers</summary>
        /// <param name="min">The minimum that the number can be</param>
        /// <param name="max">The maximum that the number can be</param>
        /// <returns>A random number between the two spesified numbers</returns>
        public static int GenerateRandom(int min, int max)
        {
            return random.Next(min, max);
        }
}

Related Tutorials