Contents

조회 수 68108 댓글 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 [ios] 최신 UI 모음.. (나중에 정리할 것) secret hooni 2013.08.09 0
776 Develop [ios] UI컨트롤러 샘플코드 hooni 2013.08.08 15478
775 Develop [ios] libxml/tree.h file not found file hooni 2013.08.08 18763
774 Develop [ios] 소소한 팁 (Rect,Point,Path,URL 등) hooni 2013.08.08 29520
773 Develop [ios] Background 에서 네트워크 사용 file hooni 2013.07.22 11581
772 Develop [ios] App States file hooni 2013.07.22 13235
771 Etc 영어의 12 시제 (The twelve tenses of English) hooni 2013.07.12 15780
770 System/OS [mac] 컨텍스트(Context) 메뉴 "다음으로 열기" 내용 정리 hooni 2013.07.10 18888
769 Develop git 브런치 배우기 (링크) hooni 2013.07.09 20685
768 Develop GCM 사용하기 3 (JSP로 GCM 푸시 서버 만들기) 4 file hooni 2013.07.06 25411
767 Develop GCM 사용하기 2 (단말에 GCM 구현하기) file hooni 2013.07.06 23402
766 Develop [android] GCM 사용하기 1 (GCM 서비스 신청하기) file hooni 2013.07.06 51417
Board Pagination Prev 1 ... 29 30 31 32 33 34 35 36 37 38 ... 98 Next
/ 98