random1 = rand() % 11 + 10; //10 ~ 20
array1 = (int*)malloc(sizeof(int)*random1); // 10~20까지의 배열생성
array2 = (int*)malloc(sizeof(int)*random1);
for (int y = 0; y < random1; y++)
{
array2[y] = 0; //array2 0으로 초기화
}
for (int x = 0; x < random1; x++)
{
{
while (1)
{
random2 = rand() % random1 + 1;
if (array2[random2 - 1] == 0)
{
array1[x] = random2;
array2[random2 - 1] = 1;
break;
}
}
}
물론 몇개의 난수 생성할건지도 랜덤입니다
저도 블로그보다가 찾은건대
기발하길래 하나 배웠습니다.
그냥 std::iota 랑 std::random_shuffle 써라.
저건 좀 그지같은 코드인데...
초보자라서 아직 많은걸모릅니다
http://cafe.daum.net/codeinside/b8FO/100
여기 내가 만들어놓은거 참고하렴.
신박하긴 한데 굳이 저럴이유가...
감사합니다ㅎㅎ