在c ++中生成随机双精度数 [英] generate random double numbers in c++

查看:803
本文介绍了在c ++中生成随机双精度数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在c ++中生成两个双精度值之间的随机数字,这些数字应该类似于xxxxx,yyyyy。

how to generate random numbers between two doubles in c++ , these number should look like xxxxx,yyyyy .

推荐答案

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

记住每次程序启动时调用srand

Remember to call srand() with a proper seed each time your program starts.

这篇关于在c ++中生成随机双精度数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆