Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
Views 68126 Comment 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
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
385 | Develop | [js] 이미지 사이즈를 동적으로 조절.. | hooni | 2013.04.23 | 7505 |
384 | Develop | [c] 간단한 순위 루틴.. (질문에 대한 답변) | hooni | 2003.04.23 | 7497 |
383 | Develop |
[c] 격자 직사각형 넓이 구하기
![]() |
hooni | 2013.04.23 | 7490 |
382 | Develop |
[c] 파일(File) 관련 함수 샘플 코드
![]() |
hooni | 2003.04.23 | 7489 |
381 | Develop |
[c] 더블(이중) 연결리스트 예제..
![]() |
hooni | 2013.04.23 | 7486 |
380 | Develop |
[js] 부모창에서 자식창으로 문자열 전달..
![]() |
hooni | 2013.04.23 | 7483 |
379 | Develop |
[jsp] 유효성체크(Client, Server 에서)
![]() |
hooni | 2003.04.23 | 7473 |
378 | Develop | [c++] MFC 모든 헤더와 라이브러리 설명 | [교류]Programming | hooni | 2013.04.23 | 7468 |
377 | Develop |
[php] gd 프로그램.. htm 파일.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 7468 |
376 | Develop |
[ios][swift] 초간단 카달로그 앱 (Catalog App)
![]() |
hooni | 2016.06.27 | 7461 |
375 | Develop |
[c] 암호화 알고리즘 DES 구현 ㅋㅋ
![]() |
hooni | 2013.04.23 | 7453 |
374 | Develop |
[c] 지폰(gphone) 소스.. 수정(암호화)
![]() |
hooni | 2013.04.23 | 7448 |