CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: generating random even & odd numbers

1. Junior Member
Join Date
May 2016
Posts
10

## 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. Banned
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. ## 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. Junior Member
Join Date
May 2016
Posts
10

## Re: generating random even & odd numbers

Originally Posted by greenharry419
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. Junior Member
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
•