Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
조회 수 68119 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
469 | Develop | [c] 하노이탑 - 재귀함수 | hooni | 2003.04.23 | 9178 |
468 | Develop | [c] 학교 건물 최단거리 찾는 웹 연동 프로그램 | hooni | 2013.04.23 | 6828 |
467 | Develop | [c] 학생명단 관리 프로그램 소스 ㅋㅋ 1 | hooni | 2003.04.23 | 7815 |
466 | Develop | [c] 한글 문자열 출력 | hooni | 2015.11.10 | 1789 |
465 | Develop | [c] 함수 목록과 예제 소스 파일 | hooni | 2013.04.23 | 7210 |
464 | Develop | [c] 함수 요약 (검색해서 쓰세요..) | hooni | 2003.04.23 | 8834 |
463 | Develop | [c] 확인해 볼거.. ㅡ,.ㅡ; | hooni | 2013.04.23 | 7174 |
462 | Develop | [c][cpp] mfc, win32api, 예제 소스 대박 모음~ | hooni | 2013.04.23 | 8479 |
461 | Develop | [c][java] 그래픽(graphic)관련 자료와 샘플코드.. | hooni | 2013.04.23 | 9218 |
460 | Develop | [c][java] 소켓 프로그래밍(채팅 서버 C, 클라이언트 Java) | hooni | 2003.04.23 | 7030 |
459 | Develop | [c][java] 주사선 채우기 알고리즘(scan line filling algorithm) 구현 | hooni | 2013.04.23 | 8990 |
458 | Develop | [c][php] 프로세스정보와 메모리 정보 웹으로 출력하는거.. | hooni | 2013.04.23 | 6345 |