I'm trying to generate random odd numbers from the given set: 3, 5, 7, 9, 11.
I got my program to generate random numbers, but they are not odd and sometimes they are larger than 11. Can anyone explain how to generate odd numbers between 3 and 11? Where did I go wrong?
Here is my code:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main( void )
{
int x;
srand(time(NULL));
printf( "%d\n", 3 + ( rand() % 11 ) );
system("pause");
return 0;
}