Home  /  Products  /  Features  /  Random-number generator—64-bit Mersenne Twister

<-  See Stata's other features

Highlights

  • 64-bit Mersenne Twister

    • Extremely long period—219937 − 1

    • 623-dimensionally equidistributed

    • 53-bit resolution

  • Applies to random-number functions

    • For uniform variates

      • runiform()

      • runiform(a,b)

      • runiformint(a,b)

    • For logistic variates

      • rlogistic()

      • rlogistic(s)

      • rlogistic(m,s)

    • For Weibull variates

      • rweibull(a,b)

      • rweibull(a,b,g)

    • For Weibull (proportional hazards) variates

      • rweibullph(a,b)

      • rweibullph(a,b,g)

    • For exponential variates

      • rexponential(b)

    • For normal variates

      • rnormal()

      • rnormal(m)

      • rnormal(m,s)

    • And more

      • rbeta(a,b)

      • rbinomial(n,p)

      • rcauchy(b,g)

      • rchi2(df)

      • rgamma(a,b)

      • rigaussian(m,a)

      • rhypergeometric(N,K,n)

      • rlaplace(b,g)

      • rnbinomial(n,p)

      • rpoisson(m)

      • rt(df)

      • rdirichlet(r,A)

      • rpareto(a,b)

      • rdiscrete(r,c,p)

      • rgeometric(p)

Stata uses the 64-bit Mersenne Twister (MT64) as its default random-number generator. Stata previously used the 32-bit KISS generator (KISS32), and still does under version control. KISS32 is an excellent random-number generator, but the Mersenne Twister has even better properties.

The MT64 is currently the most widely used random-number generator. It has a much larger period than the majority of random-number generators, meaning that you can run simulations of simulations of simulations without ever drawing the same random numbers. In addition, the MT64 generator requires 623 dimensions to exhibit patterns. MT64S is Stata's stream random-number generator, based on MT64.

Let's see it work

Suppose we wish to generate 1,000 observations from a Weibull(3,1) distribution. We first set the number of observations and then set the seed for reproducibility.

. set obs 1000 
. set seed 2414830

We then generate our new variable. To see the results, we summarize it.

. generate weib_mt64 = rweibull(3,1)
. summarize weib_mt64

Variable Obs Mean Std. Dev. Min Max
weib_mt64 1,000 .907414 .3235842 .1243035 1.930414

Tell me more

For more information about the Mersenne Twister, see Methods and formulas.

To learn more about Stata's random-number functions and the statistical distribution functions that accompany them, see Statistical functions.

To find out more about all of Stata's Random-number functions, see the Stata Functions Reference Manual.

To find out more about Stata's stream random-number generator, see [R] set rngstream.