C Programming
lotto3.c(로또번호 추첨-100만번 섞기)
빛하루
2023. 8. 3. 09:43
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int main(void)
{
int balls[45];
for (int i = 0; i<45; i++){
balls[i] = i+1;
}
srand(time(NULL));
for (int i = 1; i<=1000000; i++){
int index1;
int index2;
while(1){
index1 = rand()%45;
index2 = rand()%45;
if (index1 != index2){
break;
}
}
int temp = balls[index1];
balls[index1] = balls[index2];
balls[index2] = temp;
}
for (int i = 0; i<7; i++){
printf("%d ",balls[i]);
}
printf("\n");
return 0;
}