在C中生成不等的随机数

Geo*_*rge 2 c random numbers

我编写了一个生成4个随机数字的程序,它应该出现在屏幕上,如下所示:从0000到9999(当然不是按升序排列!).

问题是我遇到过彼此相同的数字.我该如何解决?我只想生成10,000个数字,范围在0000到9999之间,但不是以任何顺序:只是"随机".

这是我到目前为止所写的内容:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <assert.h>
#define SIZE 10000

int main(){

    srand(time(NULL));

    int a[SIZE], b[SIZE], c[SIZE], d[SIZE], i;
    FILE *fd = fopen("combinations_rand.txt", "w");
    assert(fd);

    for(i=0; i<SIZE; i++){      
        a[i] = rand()%10; //array of first digits
        b[i] = rand()%10; //array of second digits, etc...
        c[i] = rand()%10;
        d[i] = rand()%10;
        fprintf(fd, "%d%d%d%d\n", a[i], b[i], c[i], d[i]);
     }
     fclose(fd);
}
Run Code Online (Sandbox Code Playgroud)

Bug*_*219 6

取一个10000长度的数组并存储从0到9999的元素.然后在C中随机播放数组Shuffle数组.

然后在需要时用前导零打印答案在C中打印前导0?