I am trying to create three threads. Each thread is a player and has three shots. The shots are randomly generated numbers from the thread. I have tried to this by
static int counter = 0;
static Thread player1 = new Thread(new ThreadStart(Player1Shot));
static Thread player2 = new Thread(new ThreadStart(Player2Shot));
static Thread player3 = new Thread(new ThreadStart(Player3Shot));
static readonly ThreadLocal<Random> random =
new ThreadLocal<Random>(() => new Random(Interlocked.Increment(ref counter)));
static void Main(string[] args)
{
player1.Name = "David";
player2.Name = "James";
player3.Name = "Mike";
player1.Start();
player2.Start();
player3.Start();
//Console.WriteLine("{0}", random.Value.Next());
Console.ReadLine();
}
public static void Player1Shot()
{
try
{
for (int i = 0; i < 3; i++)
{
Console.WriteLine("{0} shot {1}\n", Thread.CurrentThread.Name, random.Value.Next());
}
}
However I want the random numbers to be between 0 and 100? Is this possible?