随机浮点数生成如何在C+中生成随机浮点数?我想我可以用整数兰特除以它,这样就足够了吗?
3 回答
HUH函数
TA贡献1836条经验 获得超4个赞
rand()
RAND_MAX
float r = static_cast <float> (rand()) / static_cast <float> (RAND_MAX);
float
, X
:
float r2 = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/X));
LO
HI
:
float r3 = LO + static_cast <float> (rand()) /( static_cast <float> (RAND_MAX/(HI-LO)));
rand()
rand()
srand()
rand()
srand (static_cast <unsigned> (time(0)));
rand
srand
#include <cstdlib>
.
time
#include <ctime>
.
- 3 回答
- 0 关注
- 643 浏览
添加回答
举报
0/150
提交
取消