C ++随机双值

时间:2018-05-01 02:57:03

标签: c++

如何在.1和2.5之间创建随机双倍?

这就是我一直在尝试的。

const me = {
  name: 'nabil',
  occupation: 'programming',
  dob: '1984-12-28',
};

const you = {
  longestKey: 'blah!',
};

console.log('The object is: ', longestKeyObj([me, you]));
console.log('The key is: ', longestKey(longestKeyObj([me, you])));

1 个答案:

答案 0 :(得分:4)

现代的方法是使用随机数分布:

#include <iostream>
#include <random>

using namespace std;

int main()
{
    random_device rd;
    mt19937_64 generator(rd());
    uniform_real_distribution<double> distribution(0.1, 2.5);
    for (int i = 0; i < 10; i++)
    {
        double d = distribution(generator);
        cout << d << endl;
    }
    return 0;
}

请注意0.1 <= d < 2.5