Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
조회 수 77976 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
781 | Etc | [link] 유용한 사이트 링크. | hooni | 2013.08.19 | 130284 |
780 | Etc |
베지어 곡선 (Bezier curve)
![]() |
hooni | 2013.08.18 | 238921 |
779 | Etc | [web] 제로보드 XE 템플릿에서 if문에 대해서 알아봅시다 | hooni | 2013.08.16 | 24746 |
778 | Develop |
아이 훌레시 작업중 ㅋㅋ
![]() |
hooni | 2013.08.09 | 0 |
777 | Develop |
[ios] 최신 UI 모음.. (나중에 정리할 것)
![]() |
hooni | 2013.08.09 | 0 |
776 | Develop | [ios] UI컨트롤러 샘플코드 | hooni | 2013.08.08 | 16489 |
775 | Develop |
[ios] libxml/tree.h file not found
![]() |
hooni | 2013.08.08 | 21280 |
774 | Develop | [ios] 소소한 팁 (Rect,Point,Path,URL 등) | hooni | 2013.08.08 | 32640 |
773 | Develop |
[ios] Background 에서 네트워크 사용
![]() |
hooni | 2013.07.22 | 13153 |
772 | Develop |
[ios] App States
![]() |
hooni | 2013.07.22 | 14531 |
771 | Etc | 영어의 12 시제 (The twelve tenses of English) | hooni | 2013.07.12 | 17289 |
770 | System/OS | [mac] 컨텍스트(Context) 메뉴 "다음으로 열기" 내용 정리 | hooni | 2013.07.10 | 20361 |