Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
조회 수 68118 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
1173 | System/OS | 해커스랩 깨기.. 후후.. ㅋㅋ | hooni | 2013.04.23 | 18523 |
1172 | Etc | 플라스터(Plaster) 수업 내용 | hooni | 2016.05.24 | 0 |
1171 | Develop | 프로그램 문서 관리 (Doxygen) | hooni | 2013.04.23 | 16436 |
1170 | Develop | 프로그래밍에서 foo, bar 함수의 유래 | hooni | 2013.06.25 | 21469 |
1169 | Develop | 프로그래밍 소스 관련 사이트.. | hooni | 2013.04.23 | 16524 |
1168 | Develop | 페이팔에서 돈 찾기 (Paypal withdraw) | hooni | 2014.02.20 | 11475 |
1167 | Etc | 티스토리 테이블 html,css 구문 | hooni | 2013.11.03 | 16052 |
1166 | System/OS | 콘솔에서 패스워드 걸린 zip 압축하는 명령 | hooni | 2018.03.02 | 1126 |
1165 | System/OS | 컴파일러 수업 자료(교재 : 컴파일러 입문) | hooni | 2003.04.23 | 22072 |
1164 | Develop | 캘리포니아 운전면허 족보 | hooni | 2017.06.12 | 884 |
1163 | Etc | 캘리포니아 운전면허 문제 | hooni | 2017.07.22 | 1171 |
1162 | Develop | 최근 논문 자료 (2011/01/03, 만현형한테 보낸거..) | hooni | 2013.04.23 | 10366 |