c++ - How does this expression work: Num*rand() / RAND_MAX? -


how expression work?

 num*rand() / rand_max 

if, example, replace number 7.7, gives me values 0. 7. (double).

the rand() function generates integer value between 0 , rand_max. rand()/rand_max generates real value between 0 , 1. in following code have
0 <= val <= n n can integer or real number.

double val = n * rand()/rand_max; 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -