标签:style blog http ar io color os sp for
这个网址介绍了很多
and
范围是0-1
double X=((double)rand()/(double)RAND_MAX);
1 #include <iostream> 2 #include <iomanip> 3 #include <map> 4 #include <random> 5 6 int main() 7 { 8 std::random_device rd; 9 10 11 std::mt19937 e2(rd()); 12 13 std::uniform_real_distribution<> dist(0, 1); 14 15 std::map<int, int> hist; 16 for (int n = 0; n < 10000; ++n) { 17 ++hist[std::round(dist(e2))]; 18 } 19 20 for (auto p : hist) { 21 std::cout << std::fixed << std::setprecision(1) << std::setw(2) 22 << p.first << ‘ ‘ << std::string(p.second/200, ‘*‘) << ‘\n‘; 23 } 24 }
范围是0-1
1 #include <stdlib.h> 2 3 double randZeroToOne() 4 { 5 return rand() / (RAND_MAX + 1.); 6 }
范围是M到N
double randMToN(double M, double N) { return M + (rand() / ( RAND_MAX / (N-M) ) ) ; }
标签:style blog http ar io color os sp for
原文地址:http://www.cnblogs.com/liangliangdetianxia/p/4172223.html