Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
조회 수 68108 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
229 | Develop | [js] 스타크래프트(starcraft).. | hooni | 2013.04.23 | 6655 |
228 | Develop | [c] 웅지학원 NAT를 소스코드로.. | hooni | 2013.04.23 | 6620 |
227 | Develop | [c] 간단한 점 이동 샘플 소스코드 | hooni | 2013.04.23 | 6575 |
226 | Develop | [js] 새로고침(refresh)방법과 다른 페이지 바꾸기.. | hooni | 2003.04.23 | 6559 |
225 | Develop | [c] 민수형 소스(도메인소켓포함) | hooni | 2013.04.23 | 6536 |
224 | Develop | [php] 정규표현식 간단히 정리 | hooni | 2013.04.23 | 6498 |
223 | Develop | [c] 네트워크 보안 프로그래밍 과제 (Server,Agent,Client) | hooni | 2013.04.23 | 6486 |
222 | Develop | [c] 메세지 프로그램 (Server - Agent - Client) | hooni | 2013.04.23 | 6477 |
221 | Develop | [js] 윤동이가 만든 영어 학습(?) 프로그램 | hooni | 2013.04.23 | 6473 |
220 | Develop | [doc] C언어 문법 설명서 | hooni | 2013.04.23 | 6448 |
219 | Develop | [java] 채팅창 처럼2.. swing.. | hooni | 2013.04.23 | 6443 |
218 | Develop | [c] 다중연결 서버 만들기 #3 - poll() 사용 | hooni | 2013.04.23 | 6366 |