Home  /  Products  /  Stata 14  /  New random-number generator

The 64-bit Mersenne Twister was introduced in Stata 14.

See the latest version of the 64-bit Mersenne Twister.

See the new features in Stata 18.

New random-number generator—64-bit Mersenne Twister

New random-number generator—64-bit Mersenne Twister


  • 64-bit Mersenne Twister
    • Extremely long period—219937 − 1
    • 623-dimensionally equidistributed
    • 53-bit resolution
  • Applies to all new random-number functions
    • For uniform variates
      • 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)
  • And existing random-number functions
    • For uniform variates
      • runiform()
    • For normal variates
      • rnormal()
      • rnormal(m,s)
    • And more
      • rbeta(a,b)
      • rbinomial(n,p)
      • rchi2(df)
      • rgamma(a,b)
      • rhypergeometric(N,K,n)
      • rnbinomial(n,p)
      • rpoisson(m)
      • rt(df)

What's this about?

Stata now 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.

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 new random-number functions and the statistical distribution functions that accompany them, see Statistical distribution functions.

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

Upgrade now Order Stata