Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
조회 수 68119 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
469 | Develop | [c] kmp 활용 search | hooni | 2013.04.23 | 7434 |
468 | Develop | [c] 단기과정[01/07] 제어문, 피보나치수열 | hooni | 2003.04.23 | 7439 |
467 | Develop | [c] 지폰(gphone) 소스.. 수정(암호화) | hooni | 2013.04.23 | 7446 |
466 | Develop | [c] 암호화 알고리즘 DES 구현 ㅋㅋ | hooni | 2013.04.23 | 7451 |
465 | Develop | [c++] MFC 모든 헤더와 라이브러리 설명 | [교류]Programming | hooni | 2013.04.23 | 7461 |
464 | Develop | [php] gd 프로그램.. htm 파일.. ㅋㅋ | hooni | 2013.04.23 | 7466 |
463 | Develop | [jsp] 유효성체크(Client, Server 에서) | hooni | 2003.04.23 | 7469 |
462 | Develop | [js] 부모창에서 자식창으로 문자열 전달.. | hooni | 2013.04.23 | 7481 |
461 | Develop | [c] 더블(이중) 연결리스트 예제.. | hooni | 2013.04.23 | 7484 |
460 | Develop | [c] 격자 직사각형 넓이 구하기 | hooni | 2013.04.23 | 7485 |
459 | Develop | [c] 파일(File) 관련 함수 샘플 코드 | hooni | 2003.04.23 | 7485 |
458 | Develop | [c] 간단한 순위 루틴.. (질문에 대한 답변) | hooni | 2003.04.23 | 7495 |