This is the module that will pick a random number between 1 and 100.
1. Pick a random number
2. make sure it is between 1 and 100
3. return pick
How do we get a random number?
C provides a function to generate a random number, called rand(). The prototype is in <stdlib.h>:
int rand(void);
It is given nothing (that's what void means), and returns a random integer. Unfortunately, the number is in the range 0 to the maximum positive integer we can represent (about 2 billion).
How do we limit the range to be from 1 to 100?
Let's look at the code in class to see how this is done.
example function
int pick (int start, int stop){
//int x = rand();
int y = (rand()%(stop - start+1))+start;
return y;
}