随即问题
用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;
}