Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
조회 수 68112 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
48 | Develop | [c] 64bit 머신에서 inet_ntoa() 사용시 Segment fault 대처 방법법 | hooni | 2014.02.08 | 14259 |
47 | Develop | [c] 메시지큐(Message Queue) 설명.. (joinc) | hooni | 2013.04.23 | 14297 |
46 | Develop | [unix] 쉘 스크립트 예제 모음 | hooni | 2003.04.23 | 15001 |
45 | Develop |
[java] 입출력 스트림 1부 (문자)
![]() |
hooni | 2013.04.23 | 15339 |
44 | Develop |
[android] 안드로이드 어플 모음 ㅎㅎ
![]() |
hooni | 2013.04.23 | 16340 |
43 | Develop | [java] 입출력 스트림 3부 (오브젝트) | hooni | 2013.04.23 | 17171 |
42 | System/OS | [linux] 리눅스,유닉스 /proc/stat 파일 보는 법 | hooni | 2013.04.23 | 18010 |
41 | Develop | [ios] UIView에서 상위 UIViewController 가져오기 | hooni | 2013.09.27 | 20218 |
40 | Develop |
[vb] 문자열에서 태그 제거함수 (Visual Basic)
![]() |
hooni | 2013.04.23 | 22673 |
39 | System/OS | [linux] 리눅스, 유닉스 CPU 이용률 확인.. | hooni | 2013.04.23 | 23848 |
38 | Develop |
[c#] 웹문서 소스(html) 긁어오기
![]() |
hooni | 2013.04.23 | 24561 |
37 | System/OS | [linux] 리눅스 파일시스템과 디렉토리 설명 | hooni | 2013.04.23 | 26930 |