能不能产生三个互不相等的随机数?该如何解决

能不能产生三个互不相等的随机数?
rt

------解决方案--------------------

#include "stdafx.h"
#include <time.h>
#include <stdlib.h>
#include <iostream>
using namespace std;

void GetRandomNum(int* randomNum,int n)
{
srand( (unsigned)time(NULL) ); // 设定获取随机数的种子。
for(int i=0;i<n;i++)
{
while(true)
{
randomNum[i] = rand() ; //获得随机数
int flag = 0; //标记量,如果有相等的随机数,则次变量设为1;
for(int j = 0;j<i;j++) //循环判断是否有相等随机数
{
if(randomNum[j] == randomNum[i])
{
flag == 1;
}
}
if(flag == 1)
{
continue; //如果随机数有相等,则重新获得此随机数
}

else
{
break; //如果没有,跳出。
}

}

}


int _tmain(int argc, _TCHAR* argv[])
{

int randomNum[3];
GetRandomNum(randomNum,3);
cout<<randomNum[0]<<"***"<<endl;
cout<<randomNum[1]<<"***"<<endl;
cout<<randomNum[2]<<"***"<<endl;

}
你看看这个行不。。。
不行的话请提出意见。。。