Creating a bool random value
-
I'm in need of creating 200 bool random value (0 & 1). I'm coding like this : Random rand = new Random() rand.Next(0,2) If i run in debug mode, the values it create is really random but if i don't debug, let it run automatic, all the values is just 0 or 1. Can someone tell me why and give me the direction to solve it? Thanks!
-
I'm in need of creating 200 bool random value (0 & 1). I'm coding like this : Random rand = new Random() rand.Next(0,2) If i run in debug mode, the values it create is really random but if i don't debug, let it run automatic, all the values is just 0 or 1. Can someone tell me why and give me the direction to solve it? Thanks!
If you look closely at the documentation for the Random class, you will see that it doesn't work when calls to Next are made in quick succession. That explains your debug vs non-debug behavior. Instead of generating a random number between 0 and 2, wouldn't it be better if you generated random numbers (0 to size of int) and then converted them to binary? You can generate as many random numbers as you want until you get 200 binary digits. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
If you look closely at the documentation for the Random class, you will see that it doesn't work when calls to Next are made in quick succession. That explains your debug vs non-debug behavior. Instead of generating a random number between 0 and 2, wouldn't it be better if you generated random numbers (0 to size of int) and then converted them to binary? You can generate as many random numbers as you want until you get 200 binary digits. Regards Senthil _____________________________ My Blog | My Articles | WinMacro