Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
Views 68127 Comment 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
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
385 | Develop |
[c#] MS IE(Internet Explorer) 툴바 버튼 예제 2003/2005 두가지 버전
![]() |
hooni | 2013.04.23 | 2090 |
384 | Develop |
[c#] BFilter 툴바 소스 코드 ㅎㅎ
![]() |
hooni | 2013.04.23 | 7672 |
383 | Develop |
[c++] mfc로 만든 현재 디렉토리 읽어오기/세팅하기 (GetCurrentDirectory/SetCurrentDirectory)
![]() |
hooni | 2013.04.23 | 8524 |
382 | Develop | 다운 받아서 테스트 해볼것.. | hooni | 2013.04.23 | 9176 |
381 | Develop |
[c++] mfc 기반 멀티수납(wall)시스템 소스와 실행파일
![]() |
hooni | 2013.04.23 | 7085 |
380 | Develop | [c++] mfc 기반 레지스트리(registry) 컨트롤 예제 코드 2 | hooni | 2013.04.23 | 15383 |
379 | Develop |
[c] kmp 활용 search
![]() |
hooni | 2013.04.23 | 7439 |
378 | Develop |
[c] 문자열 str_shift 예제..
![]() |
hooni | 2013.04.23 | 6862 |
377 | Develop |
[c++] winsock을 이용한 서버,클라이언트와 ssl서버,클라이언트
![]() |
hooni | 2013.04.23 | 7643 |
376 | Develop |
[c++] mfc이용한 트레이아이콘(TrayIcon) 클래스 예제 프로젝트
![]() |
hooni | 2013.04.23 | 9278 |
375 | Develop |
[c++] mfc 이용한 트레이아이콘(TrayIcon) 클래스 예제 프로젝트
![]() |
hooni | 2013.04.23 | 8834 |
374 | Develop | [c++] mfc 이용한 기본적인 형변환 예제 | hooni | 2013.04.23 | 11510 |