Contents

조회 수 78057 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
385 Develop [c] 컴파일러 DFA구현^^ 입력 받아 실행 4 file hooni 2003.04.23 9981
384 Develop [c] 캘린더 양음 변환 함수 hooni 2003.04.23 9609
383 Develop [c] 최대공약수, 최소공배수, 서로소 구하기 (펌) hooni 2013.04.23 12272
382 Develop [c] 최대공약수 알고리즘 (유클릿) hooni 2003.04.23 10376
381 Develop [c] 최단거리 알고리즘 & 예제소스.. 13 file hooni 2013.04.23 12302
380 Develop [c] 지폰(gphone) 소스.. 수정(암호화) file hooni 2013.04.23 8294
379 Develop [c] 지나가는 패킷 잡기 hooni 2003.04.23 9774
378 Develop [c] 정수를 2진수로 변환 (재귀,비트연산) file hooni 2003.04.23 8792
377 Develop [c] 정사각배열의 서브 배열의 최대 값 구하기 file hooni 2003.04.23 8653
376 Develop [c] 전위 표기법으로 연산 예제.. file hooni 2013.04.23 10414
375 Develop [c] 재미있는 코딩.. file hooni 2003.04.23 23278
374 Develop [c] 자료구조 그래프(graph) 소스코드 - 확인해볼 것.. file hooni 2013.04.23 9522
Board Pagination Prev 1 ... 62 63 64 65 66 67 68 69 70 71 ... 99 Next
/ 99