본문 바로가기

[IT/Programming]

Random number generator (무작위 수 생성기)

반응형
# Random number generator (무작위 수 생성기) 무작위 수 (random number) 는 프로그래밍적으로 어떻게 만들 수 있을까? 우선 wiki 에 잘 정리되어 있는거 같으니 시간날때 조금 읽어봐야겄음. 암호학하고도 관련있고, 꽤나 전문적인 연구분야인듯도... (깊이 들어가면 이해하기 쉽지 않다는 말.) ## PH
  • 2015-11-23 : 천천히 정리중.
## TOC ## How to test whether it is truely random or not? 어떤식으로 정말 무작위 수인지 아닌지를 판단할까나? 혹은 좋은(?) 무작위 수 생성기인지, 나쁜(?) 무작위 수 생성기인지 판단할 수 있을까? 대충 알기론 몇 차원으로 나눠서 점을 찍다보면 무작위수가 고르게 분포하지 않는 경우가 있다거나 이런걸로 판별하는거 같던데... ## Random number in finite range 32bit random integer 를 만들어주는 함수를 구현했다고 가정하더라도 이걸 가지고 특정 범위의 random number 를 만들려고 할땐 조금 주의할 필요가 있다. [0, 10) random number 를 만들어주는 함수를 가지고 단순히 나머지 연산자 random(0,10)%7 를 이용해서 [0, 7) random number 를 만들려고 하면, {0, 1, 2} set 가 {3, 4, 5, 6} set 보다 나올 확률이 두배 더 높아지기 때문이다. 뭐 아주 큰 수의 random generator 에서 작은 수로 mod 할때는 오차가 크지는 않겠지만... 그래도 (과학적인 연구용 프로그램이라던지 해서) 아주 엄밀하게 하고 싶다면 이런것까지 주의해야 한다. 그래서 보통 int b = (int)(Math.random()*10); 요런식으로 범위를 줄이는듯? ## JAVA ``` import java.util.Math; double a = Math.random(); // [0, 1.0) : 0 (inclusive) to 1.0 (exclusive) random double number int b = (int)(Math.random()*10); // [0, 10) ```/ ``` import java.util.Random; Random random = new Random(); int a = random.nextInt(bound); // [0, bound) : 0 (inclusive) to bound (exclusive) random integer number ```/ ## WELL
Abstract: (출처 : ) Fast uniform random number generators with extremely long periods have been defined and implemented based on linear recurrences modulo 2. The twisted GFSR and the Mersenne twister are famous recent examples. Besides the period length, the statistical quality of these generators is usually assessed via their equidistribution properties. The huge-period generators proposed so far are not quite optimal in that respect. In this paper, we propose new generators, with better equidistribution and “bit-mixing” properties for equivalent period length and speed. Approximately half of the coefficients of the characteristic polynomial of these generators are nonzero. The state of our new generators evolves in a more chaotic way than for the Mersenne twister. We illustrate how this can reduce the impact of persistent dependencies among successive output values, which can be observed in certain parts of the period of gigantic generators such as the Mersenne twister. Keywords: Random number generation, linear feedback shift register, GFSR linear recurrence modulo 2, Mersenne twister.
## RRA
  1. Wiki - Random number generation
  2. 나무위키 - 난수 생성
  3. API - Java SE 8 - java.util.Random
  4. API - Java SE 8 - java.util.Math #random
  5. 표준 rand()함수보다 유용한 랜덤 생성 알고리즘 – MT, WELL
  6. Wiki - 메르센 트위스터
  7. WELL Random number generator
반응형