jeudi 4 août 2016

Meaning of ((float) rand() / (float)((1 << 31) - 1))

I'm trying to understand a C program which includes a .h file with the line

#define random                  ((float) rand() / (float)((1 << 31) - 1))

The C program also includes <math.h>.

My guess is that this simply produces a random number from a uniform distribution on the interval [0,1]; is this correct?




Aucun commentaire:

Enregistrer un commentaire