Srand and Rand not working correctly?
Hi!
For some reason my srand and rand functions in my program are returning different numbers, but only thousandths to ten thousandths apart, so not very random. A few days before however, the program was running fine. I even reinstalled my compiler, CodeBlocks.
Here is an example of a program that has this issue.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
Code:
int main(void)
{
srand(time(NULL));
double z;
z = (2.0 * rand()/RAND_MAX - 1.0) *;
printf("%f", z);
return 0;
}
this returns me values such as -0.79283 and then -0.79285
Please help!