Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
조회 수 68050 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
409 | Develop | [js] 네이버에서 그림 퍼올 때.. URL Encoding 관련ㅋㅋ | hooni | 2013.04.23 | 7223 |
408 | Develop | [php] 그래프 그리는 프로그램.. | hooni | 2013.04.23 | 8471 |
407 | Develop | [c#] 툴바 소스.. 개인적으로 만드는거.. | hooni | 2013.04.23 | 3304 |
406 | Develop | [js] 부모창에서 자식창으로 문자열 전달.. | hooni | 2013.04.23 | 7458 |
405 | Develop | [js] 이미지 사이즈를 동적으로 조절.. | hooni | 2013.04.23 | 7474 |
404 | Develop | [c++] 가짜 인증서(하나은행) 프로그램 | hooni | 2013.04.23 | 10761 |
403 | Develop | [c++] 디렉토리 내의 파일 찾기 FindFirstFile() 함수 6 | hooni | 2013.04.23 | 20587 |
402 | Develop | [c++] 웹폼(webform)전송과 http 파일 업로드 샘플 | hooni | 2013.04.23 | 33077 |
401 | Develop | [doc] 유료 방송 제어 시스템 (CAS) 발표자료 | hooni | 2013.04.23 | 8509 |
400 | Develop | [doc] 테크니컬 레포트 (BHO 취약점을 이용한 공격) 2 | hooni | 2013.04.23 | 27084 |
399 | Develop | OPT와 CAS에 대한 자료.. (교수님 메일로 보내드린 자료..) | hooni | 2013.04.23 | 13925 |
398 | Develop | [c++] BHO 프로그램 동작 원리.. 간단하게.. | hooni | 2013.04.23 | 43106 |