create a new class named "RandomHelper" which contains the following ;
1. A static member called randint that accept two integer and return a random integer between them. Make sure that the numbers are inclusive (i.e. if you call randomint(1,10) you should be able to generate both 1 and 10.
2.A static method called randdouble that accept two integer and returns a random double between them.for this method you should be able to generate number such that 1<=x<10 for the method call randdouble(1,10)
3.Call your method for another call without instantiating the class (i.e.call it just you would call math.Random() since your method are defined to be static)
using System;
class RandomHelper
{
public static int RandInt(int start, int end)
{
var rand = new Random();
return rand.Next(start, end);
}
public static double RandDouble(double start, double end)
{
var rand = new Random();
return rand.NextDouble() * end + start;
}
}
class Program
{
static void Main(String[] args)
{
Console.WriteLine(RandomHelper.RandDouble(RandomHelper.RandInt(1, 10), RandomHelper.RandInt(1, 10)));
}
}
Comments
Leave a comment