|
아래는 ...
리스트에 저장되어 있는 자료들에게 랜덤으로 의사결정 번호를 부여하는 코드 입니다.
랜덤은 그냥 발생시키는게 아니라 ... 리스트의 전체 개수에 맞게 배열을 만든다음 ...
그 배열의 순서를 마구 뒤섞었습니다.
그 다음 ... 배열을 리스트 while 문 안에서 하나하나 꺼내어서 ...
그 배열값에 따라 리스트 각각에 의사결정 번호를 부여하였습니다.
컴파일은 되는데 ... 프로그램에서 실행버튼을 클릭하니깐 ...
Access Violation 이 발생하네요.
도대체 왜 안되는지 ... 엄청난 시간동안 좌절 중 ... ㅜㅜ;;;
답변 부탁 드립니다.
//---------------------------------------------------------------------------------------------
list = head;
if (list == NULL) return false;
randomize();
int init_total = list->divn_count();
int minus_total = init_total;
int *arr_divn = (int *)malloc(sizeof(int)*init_total);// divn_cnt); //new int arr_divn[sivn_cnt*sizeof(int)];
for(int i=0 ; i<init_total ; i++) {
arr_divn[i] = i+1; //배열에 값을 부여
}
int cnt = init_total;
for(int j=0 ; j<init_total ; j++) {
int first_id = int(random(init_total) % cnt);
int second_id = --cnt;
int first = arr_divn[first_id]; //두개의 배열을 랜덤으로 선정
int second = arr_divn[second_id];
arr_divn[first_id] = second; //두개의 값을 바꿈
arr_divn[second_id] = first;
}
int sect=0;
while(list)
{
//int count = int(list->divn_count());
//int tmp_id = int(list->rand_num.search(list->id));
//int sect = probability(count, tmp_id);
//////////////////////////////////////
//Case 1.03 : 확률 자체 구현
//초기 입력수를 기준으로 90-9-1% 구분
sect = int((arr_divn[minus_total-1] / init_total) * 100);
minus_total--;
//--------------------------------------------------------------------//
if (sect >= 10) list->decision = DIV_EVENT_1;
else if (sect > 0 && sect < 10) list->decision = DIV_EVENT_2;
else list->decision = DIV_EVENT_3;
if (sect >=10) list->decision |= DIV_EVENT_4;
else if (sect > 0 && sect < 10) list->decision |= DIV_EVENT_5;
else list->decision |= DIV_EVENT_6;
list = list->next;
}
free(arr_divn);
|