Contents

Views 68041 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
랜덤함수 사용시..

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
No. Category Subject Author Date Views
537 Develop [c] 약수/최대공약수/완전수 알고리즘 hooni 2003.04.23 8861
536 Develop [c] 최대공약수 알고리즘 (유클릿) hooni 2003.04.23 8873
535 Develop [js] jQjuery $ 활용 hooni 2013.12.17 8874
534 Develop [c++] 채팅로봇 소스.. ㅋㄷㅋㄷ file hooni 2013.04.23 8878
533 Develop [c++] 바탕화면 테두리에 자석처럼 붙는 스냅효과.. file hooni 2013.04.23 8902
532 Develop [js] 밀리터리 프로그램(전역일 계산) 7 file hooni 2013.04.23 8910
531 Develop [js] 객체 머지.. hooni 2013.12.17 8963
530 Develop [c][java] 주사선 채우기 알고리즘(scan line filling algorithm) 구현 file hooni 2013.04.23 8966
529 Develop [c] 간단한 채팅(클라이언트/서버) 프로그램 소스 file hooni 2003.04.23 9068
528 Develop [c] OpenGL 직사각형(2D) 크기 확대/축소 hooni 2003.04.23 9069
527 Develop [c] 디피-헬만 키교환(Diffie–Hellman key exchange) 샘플 코드.. ㅋㄷ file hooni 2013.04.23 9109
526 System/OS [linux] 간단한 find 명령어 설명(업데이트 해야 함) hooni 2013.04.23 9111
Board Pagination Prev 1 ... 49 50 51 52 53 54 55 56 57 58 ... 98 Next
/ 98