Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
조회 수 78037 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
781 | Develop | [c] 파일(int fd)에서 개행문자 단위로 읽기 by 후리자 | hooni | 2013.04.23 | 8087 |
780 | Develop |
[c] 파일명 또는 특정 패턴을 적용
![]() |
hooni | 2016.08.03 | 2412 |
779 | Develop | [c] 파일입출력 간단한 설명 | hooni | 2003.04.23 | 13580 |
778 | Develop |
[c] 파일입출력, 링크리스트(linked list)를 이용한 주소록(도스용) 소스코드
1 ![]() |
hooni | 2003.04.23 | 13405 |
777 | Develop |
[c] 패스워드 암호화/사용자 정보 보기
![]() |
hooni | 2003.04.23 | 8143 |
776 | Develop |
[c] 패킷 에널라이저 예제 소스(성안당)
![]() |
hooni | 2013.04.23 | 7877 |
775 | Develop |
[c] 패킷 유량/프로토콜 통계 모니터링..
![]() |
hooni | 2013.04.23 | 9081 |
774 | Develop |
[c] 패킷정보출력(경로, 패킷길이, 3hand, sync, ack..)
![]() |
hooni | 2003.04.23 | 8488 |
773 | Develop |
[c] 팩토리얼 서버/클라이언트..
![]() |
hooni | 2003.04.23 | 18269 |
772 | Develop | [c] 팩토리얼.. - 재귀함수 | hooni | 2003.04.23 | 10933 |
771 | Develop |
[c] 포인터 학습용 예제 소스 코드
![]() |
hooni | 2013.04.23 | 22218 |
770 | Develop | [c] 포인터와 함수포인터에 대해.. | hooni | 2003.04.23 | 9213 |