typo
[asdevice.git] / randomgen.c
blob96e7cdae391ccee5f540b9f305e855224446dd1a
1 #include <stdlib.h>
2 #include <stdio.h>
3 #include <time.h>
5 typedef struct{
6 long aCodes[5];
7 long dCodes[5];
8 } Data;
10 long getUniqueRandom(Data* d){
11 int run = 1;
12 long rnd = 0;
14 while(run){
15 run = 0;
16 srand(time(NULL));
17 rnd = rand()%100000;
18 for(int i=0; i<5; i++){ if(rnd == (*d).aCodes[i]){run = 1;}}
19 for(int i=0; i<5; i++){ if(rnd == (*d).dCodes[i]){run = 1;}}
21 return rnd;
24 int main(void){
25 Data* d = malloc(sizeof(Data));
27 for(int i=0; i<5; i++){(*d).aCodes[i] = getUniqueRandom(d);}
28 for(int i=0; i<5; i++){(*d).dCodes[i] = getUniqueRandom(d);}
30 for(int i=0; i<5; i++){ printf("%05ld\n",(*d).aCodes[i]);}
31 for(int i=0; i<5; i++){ printf("%05ld\n",(*d).dCodes[i]);}
33 return 0;