dimanche 4 décembre 2016

How to Generate Random Binary Numbers in C++?

I am trying to implement fuction to generate random binary numbers, using the following :

srand(time(NULL)); 
int S = rand() % 2;//continuous random variable between 0 and 1

and then :

 rand()%2; 

is continuously called 2^20 times ... however im not getting proper random numbers.. any suggestions for improvement ?

Is there a data type for binary numbers or eqv.? (instead of declaring an integer)

Also, the only implementation of the seed of srand that i've seen is time(NULL) OR time(0) , is there a way to manipulate the seed to get better random numbers ?




Aucun commentaire:

Enregistrer un commentaire