I am trying to generate random numbers using c++ but they don't appear to be very random. I am of course aware that they are only pseudo random but what I have found is really not even cutting it as pseudo random. Here is my code
#include <iostream>
#include <time.h>
int main(){
srand (time(NULL));
std::cout << (double) rand() / (double) RAND_MAX;
return 0;
}
The results I get from compiling and running this cpp file always starts 0.63 followed by some seemingly random numbers.
Is there something I'm missing? Am I not initializing the random number generator correctly using srand? Why arn't the numbers random between 0 and 1?
Thanks
Aucun commentaire:
Enregistrer un commentaire