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 | 다운 받아서 테스트 해볼것.. | hooni | 2013.04.23 | 10237 |
540 | Develop |
[c++] mfc이용한 트레이아이콘(TrayIcon) 클래스 예제 프로젝트
![]() |
hooni | 2013.04.23 | 10254 |
539 | Develop | [js] jQuery 셀랙터(selector) 요약 | hooni | 2013.12.17 | 10266 |
538 | Develop | [c] 약수/최대공약수/완전수 알고리즘 | hooni | 2003.04.23 | 10271 |
537 | Develop |
[c] 다중연결 서버 만들기 #2 - select() 사용
![]() |
hooni | 2013.04.23 | 10287 |
536 | Develop |
[java] 스윙(swing)버튼 테스트 ㅋㅋ
![]() |
hooni | 2013.04.23 | 10310 |
535 | Develop | [c] 최대공약수 알고리즘 (유클릿) | hooni | 2003.04.23 | 10349 |
534 | Develop |
최근 논문 자료 (2011/01/03, 만현형한테 보낸거..)
![]() |
hooni | 2013.04.23 | 10366 |
533 | Develop |
[c] 간단한 채팅(클라이언트/서버) 프로그램 소스
![]() |
hooni | 2003.04.23 | 10403 |
532 | Develop |
[c] 전위 표기법으로 연산 예제..
![]() |
hooni | 2013.04.23 | 10404 |
531 | Develop | [php] URL/URI 관련 환경변수 | hooni | 2003.04.23 | 10422 |
530 | Develop | [js] selectbox 선택 후 input 박스에 적용 | hooni | 2013.04.23 | 10442 |