0

Can someone help me?Could someone help me write this Random10Numbers function?

Why this code can only output two lines of random numbers? I want to generate four lines, each line contains ten and the single line of random numbers does not repeat #include <stdio.h> #include <stdlib.h> #include <time.h> int index = 0; int counter[10] = {0}; int count = 1; void Random10Numbers(int *numbers,int size){ int random_num; if(count == size + 1){ count = 0; index = 0; for(int i = 0;i < size;i++){ counter[i] = 0; numbers[i] = 0; } } do{ random_num = rand() % 10; }while(counter[random_num]); counter[random_num]++; numbers[index++] = random_num; count++; } int main(){ srand(time(0)); int data[10]; int i,j; for(i=0;i<4;i++){ for(j=0;j<10;j++){ Random10Numbers(data,10); printf("%d ",data[j]); } printf("\n"); } return 0; }

23rd Dec 2021, 11:27 AM
周志桓
周志桓 - avatar
3 Answers
+ 1
This is maybe more like your way https://code.sololearn.com/c9p9L3I5DnHG/?ref=app
23rd Dec 2021, 1:49 PM
Coding Cat
Coding Cat - avatar
+ 1
https://code.sololearn.com/cvu6ZXGAH7Tx/?ref=app
23rd Dec 2021, 1:01 PM
Coding Cat
Coding Cat - avatar
+ 1
Coding Santa thank you very much!
23rd Dec 2021, 2:36 PM
周志桓
周志桓 - avatar