d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Randomization Problem > C#
Prev12
Add Reply New Topic New Poll
Member
Posts: 129
Joined: Dec 7 2012
Gold: 0.00
Dec 28 2012 09:52pm
Quote (squirrel @ Dec 28 2012 03:48pm)
I didn't bother reading the other replies... so this was probably already said... but...

When you declare the random object... it creates a time seed... based on the current time... then when it generates a random number... it bases it off of that... so... if you declare to random objects beside each other... and call both of their "Next" functions... they will likely generate the same number.. HOWEVER... if you call the "Next" function twice on the same object... it will generate a new number based on the seed... so it will generate two different numbers.

TL;DR
Declare your Random object outside the function, and just call the Next() function on it.


Quote (Kalei @ Dec 9 2012 11:58am)
Problem solved.  Declared r as a field of my form. Got him out of the function.


:)
Go Back To Programming & Development Topic List
Prev12
Add Reply New Topic New Poll