Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
조회 수 68109 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
381 | Develop |
[c] 숫자 맞추는 게임..
![]() |
hooni | 2013.04.23 | 6946 |
380 | Develop |
[php] 빔 프로젝터 예약 프로그램.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 6945 |
379 | Develop | [js] php의 number_format() 함수와 같은.. ㅋㅋ | hooni | 2013.04.23 | 6942 |
378 | Develop |
[c] 도메인(호스트)으로 IP정보 알아오기.. (nslookup과 비슷)
![]() |
hooni | 2013.04.23 | 6941 |
377 | Develop | [c] 소켓의 세가지 동작모드 | hooni | 2003.04.23 | 6934 |
376 | Develop |
[c] 프로세스 정보 출력하기..
![]() |
hooni | 2003.04.23 | 6933 |
375 | Develop |
[c] 단기과정[01/10] 과제.. swap(any data, ..)
![]() |
hooni | 2003.04.23 | 6931 |
374 | Develop |
[c] 맵서치인 듯(옛날 컴에서 찾은 자료)
![]() |
hooni | 2013.04.23 | 6912 |
373 | Develop |
[c] pcapdump 파일 분석 하는 프로그램.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 6910 |
372 | Develop | [c] 프로세스간의 통신(파이프) | hooni | 2003.04.23 | 6906 |
371 | Develop |
[js] 수명체크 프로그램 ㅋㅋ
![]() |
hooni | 2013.04.23 | 6898 |
370 | Develop | [c] 라인수 입력받아 마름모꼴 출력하기.. | hooni | 2003.04.23 | 6897 |