Hiyas,
Got a question about the rand() function. If I want to generate a random number between a range of say 0 - x how would this function look like?
Code:
#include <stdlib.h>
#include <stdio.h>
#define SEED 12345
main()
{
float x;
int n;
srand(SEED);
x = rand() / RAND_MAX;
n = 1 + (int) (6 * x);
printf("x = %d", n);
}
I'm using the gcc/g++ compiler but it doesn't seem to know what RAND_MAX is (which I believe is the largest random number possible). Of course I will include time.h and based the seed on time, i.e. srand(time);
Update: Just found the solution I believe - http://www.cprogramming.com/tutorial/random.html
Cheers, Mike