Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
조회 수 78048 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
231 | Develop | [vbs] CD롬 뱉는 스크립트.. | hooni | 2003.04.23 | 12672 |
230 | Develop | [c++] String Tokenizer (나중에 c 코드로 변경해서 사용할 것) | hooni | 2013.04.23 | 12693 |
229 | Develop | [c++] 기초강좌 #02(레퍼런스,메모리할당) | hooni | 2003.04.23 | 12697 |
228 | Develop | [c++] RSA Sample 4 CPP | hooni | 2013.04.23 | 12732 |
227 | Develop | [php] 배열 관련 함수 설명 ㅎㅎ | hooni | 2003.04.23 | 12749 |
226 | Develop |
페이팔에서 돈 찾기 (Paypal withdraw)
![]() |
hooni | 2014.02.20 | 12755 |
225 | Develop |
[c] 테트리스(Tetris) 게임(도스용) 소스코드
![]() |
hooni | 2003.04.23 | 12781 |
224 | Develop |
[c] 시간 관련 함수 설명과 예제..
![]() |
hooni | 2003.04.23 | 12785 |
223 | Develop | [c++] 기초강좌 #04(클래스) | hooni | 2003.04.23 | 12809 |
222 | Develop | [php] whois정보 조회 프로그램 | hooni | 2003.04.23 | 12839 |
221 | Develop |
[swift] NotificationCenter 간단 예제
![]() |
hooni | 2021.01.27 | 12858 |
220 | Develop | [unix] 유닉스 명령에 메타문자 사용 | hooni | 2014.02.19 | 12867 |