Making these method spit odd numbers

closed account (oy721hU5)
How can I make this method do three-digit odd numbers... any suggestions?

1
2
3
4
5
6
7
8
9
10
11
12
  void GenerateThreeDigitNumbers()
		{
			int k,m;

			for ( k = 0; k < Row; k++)
			{
				for ( m = 0; m < Col; m++ )
				{
					Numbers[k][m] = rand() % 900 + 100;
				}
			}
		}
You need 3-digits numbers. That is 100-999
You need odd numbers. That means you can generate even numbers in range 100-998 and add 1
To generate even number, generate any number and multiply by 2
To generate even number in range 100-998, generate number in range 50-499 first

Your rand expression should look like: 2 * (rand() % 449 + 50) + 1 or 2 * (rand() % 449) + 101
Last edited on
Topic archived. No new replies allowed.