Results 1 to 2 of 2

Thread: Do loops?

  1. #1

    Thread Starter
    Banned timeshifter's Avatar
    Join Date
    Mar 2004
    Location
    at my desk
    Posts
    2,465

    Do loops?

    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:

    Code:
            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?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Do loops?

    Have you met my friend MSDN?

    http://search.microsoft.com/results....q=do+loop+C%23

    As for generating unique random selections:

    http://www.vbforums.com/showthread.p...87#post2394487
    Last edited by jmcilhinney; Feb 4th, 2007 at 04:42 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width