PDA

Click to See Complete Forum and Search --> : Do loops?


timeshifter
Feb 4th, 2007, 01:33 PM
Do they exist in C#? And if so, how are they coded?

The goal is to create a random number that is distinct from any number in a different array. I got the array to create six distinct numbers fairly easily, but this has me stumped. Here's what I have so far:


private void GenerateRandomNumbers()
{
for (int i = 0; i < 6; i++)
{
myNumbers[i] = myRandom.Next(1, 46);
for (int j = 0; j < i; j++)
{
if (myNumbers[i]==myNumbers[j])
{
i = i - 1;
}
}
} //fills the int array with random numbers

bonusNum = myRandom.Next(1, 46); //creates the bonus number
PopulateLabels(); //populates the labels
}

bonusNum needs to be distinct from any number in myNumbers. Any ideas?

jmcilhinney
Feb 4th, 2007, 03:39 PM
Have you met my friend MSDN?

http://search.microsoft.com/results.aspx?mkt=en-AU&setlang=en-AU&q=do+loop+C%23

As for generating unique random selections:

http://www.vbforums.com/showthread.php?p=2394487#post2394487