Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
조회 수 68050 댓글 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
-
[c] 파일입출력 간단한 설명
-
[c] 파일입출력, 링크리스트(linked list)를 이용한 주소록(도스용) 소스코드
-
[c] 패스워드 암호화/사용자 정보 보기
-
[c] 패킷 에널라이저 예제 소스(성안당)
-
[c] 패킷 유량/프로토콜 통계 모니터링..
-
[c] 패킷정보출력(경로, 패킷길이, 3hand, sync, ack..)
-
[c] 팩토리얼 서버/클라이언트..
-
[c] 팩토리얼.. - 재귀함수
-
[c] 포인터 학습용 예제 소스 코드
-
[c] 포인터와 함수포인터에 대해..
-
[c] 프로그래밍 ppt, 스킬업 (비트 수업자료)
-
[c] 프로그래밍 과제..(colprint)