<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi all,<div><br></div><div>I am redirecting a discussion on github issue tracker here.  My original post (<a href="https://github.com/numpy/numpy/issues/3137">https://github.com/numpy/numpy/issues/3137</a>):</div><div><br></div><div><span style="color: rgb(51, 51, 51); font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 13px; line-height: 20px; background-color: rgb(251, 251, 251); ">"The current implementation of the RNG seems to be MT19937-32. Since 64-bit machines are common nowadays, I am suggesting adding or upgrading to MT19937-64.  Thoughts?"</span></div><div><br></div><div><font color="#333333" face="Helvetica, arial, freesans, clean, sans-serif"><span style="font-size: 13px; line-height: 20px;">Let me start by answering to njsmith's comments on the issue tracker:</span></font></div><div><br></div><div><blockquote type="cite"><span style="background-color: rgb(251, 251, 251); color: rgb(51, 51, 51); font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 13px; line-height: 19px; white-space: pre-wrap; ">Would it be faster?</span></blockquote><br></div><div>Although I have not benchmarked the 64-bit implementation, it is likely that it will be faster on a 64-bit machine since the number of iteration (controlled by NN and MM in the reference implementation <a href="http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/C-LANG/mt19937-64.c">http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/VERSIONS/C-LANG/mt19937-64.c</a>) is reduced by half.  In addition, each generation in the 64-bit implementation produces a 64-bit random int which can be used to generate double precision random number.  Unlike the 32-bit implementation which requires generating a pair of 32-bit random int.</div><div><br></div><div>But, on a 32-bit machine, a 64-bit instruction is translated into 4 32-bit instructions; thus, it is likely to be slower.  (1)</div><div><span style="background-color: rgb(251, 251, 251); color: rgb(51, 51, 51); font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 13px; line-height: 19px; white-space: pre-wrap; "><br></span></div><div><blockquote type="cite"><span style="background-color: rgb(251, 251, 251); color: rgb(51, 51, 51); font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 13px; line-height: 19.5px; white-space: pre-wrap; ">Use </span><span style="background-color: rgb(251, 251, 251); color: rgb(51, 51, 51); font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 13px; line-height: 19.5px; white-space: pre-wrap; ">less memory?</span></blockquote><br></div><div>The amount of memory use will remain the same.  The size of the RNG state is the same.</div><div><span style="background-color: rgb(251, 251, 251); color: rgb(51, 51, 51); font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 13px; line-height: 19.5px; white-space: pre-wrap; "><br></span></div><div><blockquote type="cite"><span style="background-color: rgb(251, 251, 251); color: rgb(51, 51, 51); font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 13px; line-height: 19px; white-space: pre-wrap; ">Provide higher quality randomness?</span></blockquote></div><div><span style="background-color: rgb(251, 251, 251); color: rgb(51, 51, 51); font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 13px; line-height: 19px; white-space: pre-wrap; "><br></span></div><div><span style="background-color: rgb(251, 251, 251); color: rgb(51, 51, 51); font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 13px; line-height: 19px; white-space: pre-wrap; ">My naive answer is that 32-bit and 64-bit implementation have the same 2^19937-1 period.  Need to do some research and experiments.</span></div><div><br></div><div><blockquote type="cite"><span style="color: rgb(51, 51, 51); font-family: Helvetica, arial, freesans, clean, sans-serif; font-size: 13px; line-height: 19px; white-space: pre-wrap; background-color: rgb(251, 251, 251); ">Would it change the output of this program:
  import numpy
  numpy.random.seed(0)
  print numpy.random.random()
?</span></blockquote><br></div><div>Unfortunately, yes.  The 64-bit implementation generates a different random number sequence with the same seed. (2)</div><div><br></div><div><br></div><div>My suggestion to overcome (1) and (2) is to allow the user to select between the two implementations (and possibly different algorithms in the future).  If user does not provide a choice, we use the MT19937-32 by default.</div><div><br></div><div>        numpy.random.set_state("MT19937_64", …)   # choose the 64-bit implementation</div><div><span class="Apple-tab-span" style="white-space:pre">      </span></div><div>Thoughts?</div><div><br></div><div>Best,</div><div>Siu </div><div><br></div></body></html>