im having problems with the following code
it works fine when i have the sleep in
but without the sleep it writes the same number twice
does this have something to do with the way the computer generates the random number? like based on the computers time?
using System;
using System.Threading;
namespace RandomNumber
{
class RandNum
{
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Random number pairs from 1-6 - type \"q\" to quit");
Console.WriteLine("{0}, {1}", GetRandNum(1,6), GetRandNum(1,6));
string p = "";
while(p != "q")
{
p = Console.ReadLine();
if(p == "")
{
Console.WriteLine("{0}, {1}", GetRandNum(1,6), GetRandNum(1,6));
}
}
static int GetRandNum(int iStart, int iEnd)
{
Random r = new Random();
// //sleeping helps generate random number
Thread.Sleep(r.Next(100));
int i = r.Next(iStart, iEnd * iEnd);
i = i/iEnd + 1;
return i;
}
}
}