随即问题
用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;
}
还有为什么 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;
}
...全文
相关推荐
完美解决mysql启动后随即关闭的问题(ibdata1文件损坏导致)
下面小编就为大家带来一篇完美解决mysql启动后随即关闭的问题(ibdata1文件损坏导致)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
密码随即申请器
密码随即申请器可以生成多少方式
串口通讯测试,发送随即乱码
串口通讯测试,发送随即乱码,用于测试串口通讯设备的程序的健壮性、可靠性。确保任何不满足通讯协议的信息不会对设备进行破坏
执行随即机生产消费者进程
生产消费进程,一次产生5个随即进程,判断知否能够执行,产品放在缓存区里
优化设计随即方向法
添加了时间种子做到真随即,程序简单自己看的走一下吧。


