c++如何产生0到1之间的随机数?用什么指令?

2025-04-04 16:27:34
推荐回答(1个)
回答1:

测试通过

#include
#include

using namespace std;

int main()
{
double number;
srand((unsigned)time(NULL));

for(int i = 0;i < 10;i++)
{
number = ((double)(rand() % 10)) / 10;//将0~10之间的随机数除以10
cout< }

system("pause");
return 0;
}