Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
Views 68116 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 |
---|---|---|---|---|---|
36 | Develop | [java] 입출력 스트림 3부 (오브젝트) | hooni | 2013.04.23 | 17176 |
35 | Develop | [json] 종결자 (설명과 웹, C/C++/C# 프로그램 샘플 코드) | hooni | 2013.04.23 | 72033 |
34 | Develop | [js] 웹페이지에서 특정 엘리먼트 드래그, 복사, 컨텍스트메뉴, 키보드 막기 | hooni | 2013.11.04 | 30126 |
33 | Develop | [lego] 세그웨이 이것만 볼것.. ㅎㅎ | hooni | 2013.04.23 | 33581 |
32 | System/OS | [linux] 리눅스 파일시스템과 디렉토리 설명 | hooni | 2013.04.23 | 26934 |
31 | System/OS | [linux] 리눅스, 유닉스 CPU 이용률 확인.. | hooni | 2013.04.23 | 23852 |
30 | System/OS | [linux] 리눅스,유닉스 /proc/stat 파일 보는 법 | hooni | 2013.04.23 | 18014 |
29 | System/OS | [linux] 초간단 Postfix, Covecot, SSL/TLS (SMTP) | hooni | 2017.12.11 | 9505 |
28 | System/OS | [linux] 특정 문자열 포함된 파일 찾는 명령어 | hooni | 2013.10.16 | 30716 |
27 | System/OS | [mac] Mac OS에서 재생되는 사운드를 녹음하는 방법 | hooni | 2016.10.03 | 1734 |
26 | System/OS | [mac] Mac에서 Mac으로 원격제어하기 (맥에서 맥으로) | hooni | 2013.10.08 | 37250 |
25 | System/OS | [mac] OS X 엘 캐피탄에서 Soudflower 사용하기 2 | hooni | 2016.10.03 | 1167 |