Contents

조회 수 68056 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
랜덤함수 사용시..

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


?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
777 Develop [c] 파일입출력 간단한 설명 hooni 2003.04.23 11245
776 Develop [c] 파일입출력, 링크리스트(linked list)를 이용한 주소록(도스용) 소스코드 1 file hooni 2003.04.23 11154
775 Develop [c] 패스워드 암호화/사용자 정보 보기 file hooni 2003.04.23 7016
774 Develop [c] 패킷 에널라이저 예제 소스(성안당) file hooni 2013.04.23 6948
773 Develop [c] 패킷 유량/프로토콜 통계 모니터링.. file hooni 2013.04.23 8376
772 Develop [c] 패킷정보출력(경로, 패킷길이, 3hand, sync, ack..) file hooni 2003.04.23 7246
771 Develop [c] 팩토리얼 서버/클라이언트.. file hooni 2003.04.23 17286
770 Develop [c] 팩토리얼.. - 재귀함수 hooni 2003.04.23 9503
769 Develop [c] 포인터 학습용 예제 소스 코드 file hooni 2013.04.23 21036
768 Develop [c] 포인터와 함수포인터에 대해.. hooni 2003.04.23 8019
767 Develop [c] 프로그래밍 ppt, 스킬업 (비트 수업자료) file hooni 2003.04.23 8179
766 Develop [c] 프로그래밍 과제..(colprint) file hooni 2003.04.23 6745
Board Pagination Prev 1 ... 29 30 31 32 33 34 35 36 37 38 ... 98 Next
/ 98