晕```。为什么我循环时,每个随机数都一样的? 帮我看下错哪了
这步都不会,下面的写不下去啊
//类文件:
#include <stdlib.h>
#include "time.h"
class RandomInt
{
public:
RandomInt();
RandomInt(int n,int m);
static double diem(int n,int m);
static double dien(int n,int m);
};
inline double RandomInt::diem(int n,int m)
{
return rand()%m+n;
}
inline double RandomInt::dien(int n,int m)
{
return rand()%m+n;
}
/************************/
函数:
#include <iostream>
#include "RandomInt.h"
#include "time.h"
using namespace std;
void main()
{
srand((unsigned)time(NULL));
int die1=RandomInt::diem(1,6),
die2=RandomInt::dien(1,6);
cout <<"请输入抛掷次数:";
int n;
cin >>n;
cout <<"得出随即数为:"<<"\n";
for(int i=1;i<=n;i++)
cout <<die1<<"\n"
<<die2 <<"\n\n";
}
//如果我直接用:
for(int i=1;i<=n;i++)
cout <<RandomInt::diem(1,6)
<<RandomInt::diem(1,6);
他就能循环出不同的随机数,为什么赋值给die1,die2后就不行了?