Develop
2013.10.31 16:51
[ios] Random Thoughts: Rand() vs. arc4random()
조회 수 78021 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
541 | Develop | [iphone] 화면 전환 Portrait & Landscape Mode | hooni | 2013.04.23 | 23395 |
540 | Develop |
[Javascript][Ajax] 자바스크립트 강의 산출물
![]() |
hooni | 2019.10.05 | 3036 |
539 | Develop | [java] Interface 와 abstract | hooni | 2013.04.23 | 11273 |
538 | Develop | [java] netty (비동기 이벤트 방식 네트워크 프레임워크) 사용법 #1 (server) 1 | hooni | 2015.01.02 | 4318 |
537 | Develop | [java] netty (비동기 이벤트 방식 네트워크 프레임워크) 사용법 #2 (client) | hooni | 2015.01.02 | 3540 |
536 | Develop |
[java] RGB 색상 조절 버튼.. 스윙(swing)
![]() |
hooni | 2013.04.23 | 10208 |
535 | Develop | [java] RGB코드를 HEX코드로 변환하는 코드 ㅎㅎ | hooni | 2013.04.23 | 9230 |
534 | Develop | [java] Sieve of Eratosthenes (에라토스테네스의 체) | hooni | 2013.04.23 | 10464 |
533 | System/OS | [java] Tomcat/UTF-8 or All 지원 ㅎㅎ | hooni | 2013.04.23 | 17660 |
532 | Develop |
[java] 거스름돈 계산.. swing 사용
![]() |
hooni | 2013.04.23 | 10657 |
531 | Develop |
[java] 그래픽(도형,다각형..) 이동,확대,축소,회전에 대한 내용..
1 ![]() |
hooni | 2013.04.23 | 9886 |
530 | Develop | [java] 날짜 계산 (Date, SimpleDateFormat) | hooni | 2013.04.23 | 13017 |