Hi,
I am a beginner in C# and am desperately looking for help.
Basically, I do not understand why the following line in this method below:
why NextDouble() has to multiply by (n - 1) + 1?
Hope someone can explain to me.
Thanks.
I am a beginner in C# and am desperately looking for help.
Basically, I do not understand why the following line in this method below:
public static void Main(string [] args)
{
Console.Write("Enter a number: ");
int n = Convert.ToInt32(Console.ReadLine());
Random random = new Random();
double g = random.NextDouble() * (n - 1) + 1;
while (Maths.Abs(g*g - n) > 0.00001)
{
g = (g + n/g)/2;
}
Console.WriteLine(g);
}
why NextDouble() has to multiply by (n - 1) + 1?
Hope someone can explain to me.
Thanks.
Last edited by a moderator: