Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
조회 수 68108 댓글 0
랜덤함수 사용시..
iOS
There are several built-in randomizers on the iPhone, and most people's first thought is to use rand() after seeding it by calling
srandom(time(NULL));
But... rand() is really not a very good PRNG. random() is a little better, but still less then ideal. Fortunately, these are not the only ones available on the iPhone. Personally, I like arc4random() because it's a decent pseudo-random algorithm and has twice the range or rand().
On the iPhone, RAND_MAX is 0x7fffffff (2147483647), while arc4random() will return a maximum value of 0x100000000 (4294967296), giving much more precision. You also don't need to seed arc4random(), as the first call to it automatically seeds it.
결론은 arc4random() 을 사용하자.
[출처] http://iphonedevelopment.blogspot.com/2008/10/random-thoughts-rand-vs-arc4random.html
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
385 | Develop |
[c]디렉토리 탐색
![]() |
hooni | 2003.04.23 | 7325 |
384 | Develop |
[c][php] 프로세스정보와 메모리 정보 웹으로 출력하는거..
![]() |
hooni | 2013.04.23 | 6337 |
383 | Develop |
[c][java] 주사선 채우기 알고리즘(scan line filling algorithm) 구현
![]() |
hooni | 2013.04.23 | 8974 |
382 | Develop |
[c][java] 소켓 프로그래밍(채팅 서버 C, 클라이언트 Java)
![]() |
hooni | 2003.04.23 | 7026 |
381 | Develop |
[c][java] 그래픽(graphic)관련 자료와 샘플코드..
![]() |
hooni | 2013.04.23 | 9212 |
380 | Develop |
[c][cpp] mfc, win32api, 예제 소스 대박 모음~
![]() |
hooni | 2013.04.23 | 8474 |
379 | Develop |
[c] 확인해 볼거.. ㅡ,.ㅡ;
![]() |
hooni | 2013.04.23 | 7173 |
378 | Develop | [c] 함수 요약 (검색해서 쓰세요..) | hooni | 2003.04.23 | 8825 |
377 | Develop |
[c] 함수 목록과 예제 소스 파일
![]() |
hooni | 2013.04.23 | 7202 |
376 | Develop | [c] 한글 문자열 출력 | hooni | 2015.11.10 | 1780 |
375 | Develop |
[c] 학생명단 관리 프로그램 소스 ㅋㅋ
1 ![]() |
hooni | 2003.04.23 | 7795 |
374 | Develop |
[c] 학교 건물 최단거리 찾는 웹 연동 프로그램
![]() |
hooni | 2013.04.23 | 6813 |