난 이상한 동작을합니다. 난수 생성을 시도합니다. 그리고 때로는 완전히 같음 또는 동일한 시간에 생성 된 경우 문제가 있습니까? VC 2,012C 난수 생성기가 때때로 동일한 숫자를 생성합니다
for (int i = array_size; i < (array_size); i++)
{
srand((unsigned int)time(NULL));
int rw = rand() % 960 + (20); //returns a pseudo-random integer between x resolution size 0 -> width
int rh = rand() % 640 + (20); //returns a pseudo-random integer between x resolution size 0 -> height
lwsl_notice("c:%d width %d height %d\n",c, rw, rh);
c++;
}
를 사용한 경우의 출력은 : for
루프 밖으로
[2016/06/30 09:39:09:7274] NOTICE: c:0 width 606 height 567
[2016/06/30 09:39:09:7274] NOTICE: c:1 width 606 height 567
[2016/06/30 09:39:09:7274] NOTICE: c:2 width 606 height 567
[2016/06/30 09:39:09:7274] NOTICE: c:3 width 606 height 567
루프 밖에서'srand'를 사용해야합니다. – ameyCU
oops 더 정확한 dup은 [모든 루프 반복마다 동일한 임의의 숫자] (http://stackoverflow.com/q/9251117/995714), [rand()는 여러 함수 호출에서 일관됨] (http://stackoverflow.com (srand (time (NULL))은 시드 값을 충분히 빠르게 변경하지 않습니다.] (http://stackoverflow.com/q/5574914/995714), [srand()] once?] (http://stackoverflow.com/q/7343833/995714) –