Answer to Question #326385 in C# for vijay

Question #326385

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)


1
Expert's answer
2022-04-10T05:24:51-0400
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)));
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS