c++中怎么产生0-1之间的随机数
2015-03-03 12:58
309 查看
http://zhidao.baidu.com/question/688719686574659564.html
#include <iostream> #include <time.h> using namespace std; double GetRand(); int main() { cout << GetRand() << endl; return 0; } double GetRand() { srand(time(NULL)); int iRand = rand(); iRand %= 10000; // 取0 ~ 9999 return iRand / 10000.0; // 注意加".0" // PS:保留几位小数就合适求舍,求商 }
相关文章推荐
- C++产生8到22之间的随机数
- FW:0到1之间的随机数是怎么产生的
- C++产生m到n之间的随机数,产生0到100之间的随机数,以系统时间作为随机种子
- C/C++怎么产生随机数【转】
- C/C++怎样产生任意指定范围的随机数?
- C语言/C++中怎样产生随机数
- C语言/C++中怎样产生随机数
- C++产生随机数的方法
- C++连续产生不同的随机数
- C++中产生一定范围内的随机数
- C/C++中怎样产生随机数
- C++产生正态分布的随机数
- C/C++中产生随机数(rand,srand用法)
- 产生a到b之间均匀分布的随机数
- C/C++产生随机数
- [转]C/C++中产生随机数(rand,srand用法)
- C语言/C++中怎样产生随机数
- c/c++随机数产生相同解决方案
- C语言/C++中怎样产生随机数
- 产生a到b之间均匀分布的随机数