随即问题

Kotoya Kotoya 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
用randomize()的时候要加什么头文件吗? 书上没写啊 不是直接就可以用吗?
还有为什么 RAND_MAX 是对的 LRAND_MAX 就有问题啊 还有random(n)不是和
rand()%n 一样吗? 要怎么改
:\作业\9\1212.cpp(29) : error C2065: '_LRAND_MAX' : undeclared identifier
D:\作业\9\1212.cpp(39) : error C2065: 'randomize' : undeclared identifier
D:\作业\9\1212.cpp(7) : error C2065: 'random' : undeclared identifier
#include <iomanip>
#include <iostream>
#include <cstdlib>
using namespace std;

inline int RandI(int N)
{return random(N)+1;}

void TestDice();
const int TestNum = 6000;

int main()
{
cout << setiosflags(ios::right)
<< setiosflags(ios::fixed)
<< setiosflags(ios::showpoint)
<< std::setprecision(4);
cout << "RAND_MAX (0x7FFFU) 的值是 :"
<< setw(7) << RAND_MAX << endl;
cout << "LRAND_MAX (0x7FFFFFFFU) 的值是 :"
<< setw(7) << LRAND_MAX << endl;
TestDice();
return 0;
}

void TestDice()
{
int Freq[6], Face, i;
for (i=0; i<6; i++) Freq[i]=0;

randomize();

cout << "连掷 20 次的结果: " << endl;
for (i=1; i<=20; i++)
{
cout << setw(5) << RandI(6);
if (i%5 == 0) cout << endl;
}
cout << endl;

for (int Roll=0; Roll< TestNum; Roll++)
{
Face = RandI(6);
Freq[Face-1]++;
}
cout << " 点数 次数 " << endl;
cout << "------------------ " << endl;
for (i=0; i<6; i++)
cout << setw(5) << (i+1)
<< setw(10) << Freq[i] << endl;
cout << "------------------ " << endl;
}
...全文
评论 3
收藏 已收藏
分享
返回顶部
Kotoya
C语言 70,040 成员 243,237 内容