dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: generating random even & odd numbers

  1. #1
    Join Date
    May 2016
    Posts
    10

    Question generating random even & odd numbers

    Hi it's my first post,and obviously i have an issue with the following code not generating numbers but i want to specify if it's odd or even,and the sum of the combination cause i am generating a round 10 numbers at time,
    //private void generateNumbers()
    {
    val = numGen.Next(1, 70);
    num1.Text = val.ToString();
    val = numGen.Next(1, 70);
    while (val.ToString().Equals(num1.Text))
    val = numGen.Next(1, 70);
    num2.Text = val.ToString();

    i appreciate the help immensely'
    My regards

  2. #2
    Join Date
    May 2016
    Location
    Navi Mumbai
    Posts
    10

    Re: generating random even & odd numbers

    Not ready with the full answer, but to check whether the number is even, you can use the modulus operator by checking if the number % 2 == 0 then the number is even

  3. #3
    Join Date
    Jan 2010
    Posts
    1,133

    Re: generating random even & odd numbers

    You don't have to directly generate even or odd numbers - you can just generate some random numbers and make even or odd numbers from them.

    Even: 2*n
    Odd: 2*n + 1

    Just make your own methods that do that, and adjust the ranges, etc.

  4. #4
    Join Date
    May 2016
    Posts
    10

    Re: generating random even & odd numbers

    Quote Originally Posted by greenharry419 View Post
    Not ready with the full answer, but to check whether the number is even, you can use the modulus operator by checking if the number % 2 == 0 then the number is even
    "I appreciate the effort,My regards"

  5. #5
    Join Date
    May 2016
    Posts
    10

    Re: generating random even & odd numbers

    "thank you it's highly appreciated"

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)