码迷,mamicode.com
首页 > 编程语言 > 详细

c++获取浮点数随机数

时间:2020-11-13 12:42:56      阅读:7      评论:0      收藏:0      [点我收藏+]

标签:color   orm   for   distrib   iostream   div   cout   sig   standard   

#include <random>
#include <iostream>
 
int main()
{
    std::random_device rd;  //Will be used to obtain a seed for the random number engine
    std::mt19937 gen(rd()); //Standard mersenne_twister_engine seeded with rd()
    std::uniform_real_distribution<> dis(1.0, 2.0);
    for (int n = 0; n < 10; ++n) {
        // Use dis to transform the random unsigned int generated by gen into a 
        // double in [1, 2). Each call to dis(gen) generates a new random double
        std::cout << dis(gen) <<  ;
    }
    std::cout << \n;
}

 

c++获取浮点数随机数

标签:color   orm   for   distrib   iostream   div   cout   sig   standard   

原文地址:https://www.cnblogs.com/iwana/p/13915594.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!