Paste the code for your generateRandomValue(); method. The problem is likely that when you have a break point that one second passes on your computers clock that changes the seed value for generateRandomValue(). You probably should use another GetRandomValue() method:
private void simpleButton4_Click(object sender, EventArgs e)
{
List<int> lst = new List<int>();
for (int i1 = 0; i1 < 10; i1++)
{
lst.Add(GetRandom(10));
}
System.Diagnostics.Debugger.Break();
}
public static int GetRandom(int Maxvalue)
{
byte[] randomNumber = new byte[1];
System.Security.Cryptography.RNGCryptoServiceProvider Gen = new System.Security.Cryptography.RNGCryptoServiceProvider();
Gen.GetBytes(randomNumber);
int rand = Convert.ToInt32(randomNumber[0]);
return rand % Maxvalue + 1;
}
I suspect you are using the "Random" class. This is a quote from the help file:However, because the clock has finite resolution, creating different Random objects in close succession creates random number generators that produce identical sequences of random numbers. This problem can be avoided by creating a single Random object rather than multiple ones.
This would explain why debugger breaks would change the values since the clock would change in time between calls to generator.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
OK, then that is your problem. Change your random function to the one I posted and it should work fine.
sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735