关于数组内数值随机选取时,如何能不重复选取呢,请教

发现抽取的数值会有重复情况出现,如何避免啊,求问,总是改出乱码555555
源程序如下:

//抽奖程序

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include<math.h>
#include <fstream>
#include <iostream>
#include <iomanip>
using namespace std;

#define MAX_NUM 10
#define One 1
#define Two 2
#define Three 5

void suijishu(char phone[]);


int main(int argc, char * argv[])
{
    char phone[MAX_NUM][12];
    int count;
    int M;
    int flag;

    cout << "输入需要几组号码:" << endl;
    cin >> M;

    srand(time(0));
    for (count = 0; count<M; count++)
    {
        memset(phone[count], 0, sizeof(phone[count]));
        suijishu(phone[count]);
    }

    ofstream outfile("data.txt");

    for (count = 0; count<M; count++)
    {
        cout << phone[count] << endl;
        outfile << phone[count] << endl;
    }
    outfile.close();    //关闭文件
    
    //抽奖
    count = rand()%10;
    cout << "一等奖:" << phone[count] << endl;
    
    
    cout<<endl;
    
    for (count = 0; count < 2; count ++)
    {
        cout << "二等奖:" << phone[count] << endl; 
    }
    
    
    cout<<endl; 
    
    for (count = 0; count < 5; count ++)
    {
        cout << "三等奖:" << phone[count] << endl; 
    }
    return 0;
}
 
//随机数
void suijishu(char phone[])
{
    char p1[5] = {"1781"};

    strcpy(phone, "1781");

    int i;
    for (i = 4; i<11; i++)
        phone[i] = rand() % 10 + '0';
}


rand() 生成的是均匀分布,随机生成一个区间内所有数,概率相等。

可以这样做:将生成的数,加入一个set/unordered_set,每次生成以后,先查set,如果已经存在,就重新生成该数;如果不存在,就加入set。

最后,set中存在的数,就是你想要的不重复的随机数。