Sunday, July 12, 2009

How do i create two different random numbers in the same button click?

I am trying to create two different random numbers but i keep getting the same number with two different instances. This is C# btw. Here is the problematic code:





public int Roll1()


{


//Rolling the dice


System.Random Roll1 = new System.Random();


int DiceRoll1 = Roll1.Next(1, 7);


lblPlayer1Position.Text = DiceRoll1.ToString();





return 0;


}





public int Roll2()


{


//Rolling the dice


System.Random Roll2 = new System.Random();


int DiceRoll2 = Roll2.Next(1, 7);


lblPlayer2Position.Text = DiceRoll2.ToString();





return 0;


}

How do i create two different random numbers in the same button click?
Create 2 different variables then


assign first instance of random number to 1st variable then


assign next instance of random number to 2nd variable.


Viola!


No comments:

Post a Comment