Random rand = new Random(); //랜덤선언
const int max_random = 9; //10개의 랜덤수
bool[] randomValue = new bool[max_random];//수만큼 bool형 선언
for (int i = 0; i < max_random; i++)//모든 값을 false로
randomValue[i] = false;
//선언 및 초기화 부분//
malraris = randommal.Next(9);
if (randomValue[malraris] == false)//false라면 위치 정해주고
{
randomValue[malraris] = true;
person1[malrari].position = position[malraris];
}
else if (randomValue[malraris] == true) //만약 사실이라면 다시 돌리자
{
while (!randomValue[malraris] == false)//조건문이false가 될때까지 랜덤
{
malraris = randommal.Next(9);
}
randomValue[malraris] = true;
person1[malrari].position = position[malraris];
}
초기화 부분에 포지션을 9개 지정해 두었습니다.
이제 중복되지않게 차례로 랜덤하게 위치를 지정해 주었습니다.
게임제작시 많이 이용됩니다.
중복되지않고 랜덤하게 배열하는것은 참 유용하게 쓰일 듯 합니다.^^
const int max_random = 9; //10개의 랜덤수
bool[] randomValue = new bool[max_random];//수만큼 bool형 선언
for (int i = 0; i < max_random; i++)//모든 값을 false로
randomValue[i] = false;
//선언 및 초기화 부분//
malraris = randommal.Next(9);
if (randomValue[malraris] == false)//false라면 위치 정해주고
{
randomValue[malraris] = true;
person1[malrari].position = position[malraris];
}
else if (randomValue[malraris] == true) //만약 사실이라면 다시 돌리자
{
while (!randomValue[malraris] == false)//조건문이false가 될때까지 랜덤
{
malraris = randommal.Next(9);
}
randomValue[malraris] = true;
person1[malrari].position = position[malraris];
}
초기화 부분에 포지션을 9개 지정해 두었습니다.
이제 중복되지않게 차례로 랜덤하게 위치를 지정해 주었습니다.
게임제작시 많이 이용됩니다.
중복되지않고 랜덤하게 배열하는것은 참 유용하게 쓰일 듯 합니다.^^