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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
541 | Develop |
[c] GD라이브러리 설치 테스트 소스
![]() |
hooni | 2013.04.23 | 9238 |
540 | Develop | [java] RGB코드를 HEX코드로 변환하는 코드 ㅎㅎ | hooni | 2013.04.23 | 9230 |
539 | Develop |
[js] 셀렉트박스(select)의 옵션(option) 동적으로 추가/제거
![]() |
hooni | 2013.04.23 | 9228 |
538 | Develop |
[c] 구구단 최단라인 ㅡㅡ;
![]() |
hooni | 2013.04.23 | 9226 |
537 | Develop | [js] 핫키(단축키) 구현방법 | hooni | 2003.04.23 | 9224 |
536 | Develop |
[c] 퀵정렬(quick sort) 예제 소스..
![]() |
hooni | 2013.04.23 | 9223 |
535 | Develop | [c] 포인터와 함수포인터에 대해.. | hooni | 2003.04.23 | 9213 |
534 | Develop | [c++] Win32API를 이용한 ExitWindowsEx 사용한 예제코드 | hooni | 2013.04.23 | 9206 |
533 | Develop | [c] 단기과정[01/08] (다차원 + 배열)포인터, void 포인터 | hooni | 2003.04.23 | 9206 |
532 | Develop |
[vb] 64bit RSA 프로그램 소스 ㅋㅋ
![]() |
hooni | 2013.04.23 | 9200 |
531 | Develop | [c] 문자열 처리 관련 함수들 설명 | hooni | 2003.04.23 | 9187 |
530 | Develop | [js] 자바스크립트 이벤트 핸들.. | hooni | 2003.04.23 | 9161 |