Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
조회 수 68033 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
841 | Develop | 프로그램 문서 관리 (Doxygen) | hooni | 2013.04.23 | 16385 |
840 | Develop | 프로그래밍에서 foo, bar 함수의 유래 | hooni | 2013.06.25 | 21244 |
839 | Develop | 프로그래밍 소스 관련 사이트.. | hooni | 2013.04.23 | 16485 |
838 | Develop | 페이팔에서 돈 찾기 (Paypal withdraw) | hooni | 2014.02.20 | 10956 |
837 | Develop | 캘리포니아 운전면허 족보 | hooni | 2017.06.12 | 726 |
836 | Develop | 최근 논문 자료 (2011/01/03, 만현형한테 보낸거..) | hooni | 2013.04.23 | 10366 |
835 | Develop | 참고하고 지울 자료.. 집에서 바야지.. ㅋㅋ | hooni | 2013.04.23 | 12115 |
834 | Develop | 정리할 자료. | hooni | 2015.07.02 | 674 |
833 | Develop | 자주 쓰는 Docker 명령어 alias | hooni | 2020.01.10 | 268847 |
832 | Develop | 이어서 작업할 내용~ | hooni | 2013.11.21 | 0 |
831 | Develop | 웹페이지 성능 테스트 툴 설명 | hooni | 2013.04.23 | 27443 |
830 | Develop | 알고리즘 성능분석 | hooni | 2014.06.24 | 2957 |