浮点随机数产生

include

#include 
#include 

0-1

float r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);

0-X

float r2 = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/X));

L0-HI

float r3 = LO + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(HI-LO)));

种子srand

srand (static_cast <unsigned> (time(0)));

你可能感兴趣的:(Software)