Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Predictable random sequence

by BrowserUk (Pope)
on Sep 17, 2013 at 14:36 UTC ( #1054454=note: print w/ replies, xml ) Need Help??


in reply to Predictable random sequence

Use Math::Random::MT. For any given seed and argument, it will produce the same sequence of random numbers.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.


Comment on Re: Predictable random sequence
Re^2: Predictable random sequence
by vsespb (Hermit) on Sep 17, 2013 at 14:42 UTC
      but seems it's not cleared in documentation that sequence is always same for same seed.

      It does, else it wouldn't be the Mersenne Twister.

      Update: Results from a 32-bit and a 64-bit build of Perl (on windows):

      C:\test>\perl32\bin\perl -MMath::Random::MT=rand,srand -le"srand(1); p +rint rand(12345) for 1 .. 50" 0.417021998437122 0.99718480813317 0.720324489288032 0.932557361200452 + 0.000114381080493331 0.128124447772279 0.302332567749545 0.999040515394881 0.14675589255057 +3 0.236088976264 0.0923385955393314 0.39658072614111 0.186260211281478 0.38791074021719 +4 0.345560725079849 0.66974604036659 0.396767468657345 0.935539072612301 0.538816731888801 + 0.846310918219388 0.419194519054145 0.313273512991145 0.685219500679523 0.52454816270619 +6 0.204452248988673 0.44345289375633 0.878117437008768 0.22957722004503 0.027387595968321 +0.534413907211274 0.670467507559806 0.913962022401392 0.417304804315791 0.45720480917953 + 0.558689827332273 0.430698570096865 0.140386936953291 0.939127794932574 0.19810148328542 +7 0.778389235492796 0.800744566367939 0.715970510849729 0.968261571833864 0.80275750323198 +7 0.313424184685573 0.0928008102346212 0.692322616931051 0.518152548233047 0.8763891460839 +66 0.865020245313644 C:\test>\perl64\bin\perl -MMath::Random::MT=rand,srand -le"srand(1); p +rint rand(12345) for 1 .. 50" 0.417021998437122 0.99718480813317 0.720324489288032 0.932557361200452 + 0.000114381080493331 0.128124447772279 0.302332567749545 0.999040515394881 0.14675589255057 +3 0.236088976264 0.0923385955393314 0.39658072614111 0.186260211281478 0.38791074021719 +4 0.345560725079849 0.66974604036659 0.396767468657345 0.935539072612301 0.538816731888801 + 0.846310918219388 0.419194519054145 0.313273512991145 0.685219500679523 0.52454816270619 +6 0.204452248988673 0.44345289375633 0.878117437008768 0.22957722004503 0.027387595968321 +0.534413907211274 0.670467507559806 0.913962022401392 0.417304804315791 0.45720480917953 + 0.558689827332273 0.430698570096865 0.140386936953291 0.939127794932574 0.19810148328542 +7 0.778389235492796 0.800744566367939 0.715970510849729 0.968261571833864 0.80275750323198 +7 0.313424184685573 0.0928008102346212 0.692322616931051 0.518152548233047 0.8763891460839 +66 0.865020245313644

      You should get the same everywhere regardless of platform or build.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        I am getting different results on linux:
        $ perl -MMath::Random::MT=rand,srand -le"srand(1); print rand(12345) f +or 1 .. 50" 5148.13657070627 12310.246456404 8892.40582026076 11512.4206240196 1.41203443869017 1581.69630774879 3732.29554886813 12333.1551625498 1811.70149353682 2914.51841197908 1139.91996193305 4895.789064212 2299.38230826985 4788.75808798126 4265.94715111074 8268.01486832555 4898.09440057492 11549.2298513988 6651.69255516725 10447.7082854183 5174.95633772342 3867.36151787569 8459.03473588871 6475.54706860799 2523.96301376517 5474.42597342189 10840.3597598732 2834.1307814559 338.099872228922 6597.33968452318 8276.92138082581 11282.8611665452 5151.62780927843 5644.19336932129 6897.02591841691 5316.9738478458 1733.07673668838 11593.5326284426 2445.5628111586 9609.21511215856 9885.19167181221 8838.65595643991 11953.189104289 9910.04137739888 3869.2215599434 1145.6260023464 8546.72270601382 6396.59320793697 10819.0240084066 10678.6749283969
        Maybe you meant this?
        $ perl -MMath::Random::MT=rand,srand -le"srand(1); print rand() for 1 +.. 50" 0.417021998437122 0.99718480813317 0.720324489288032 0.932557361200452 0.000114381080493331 0.128124447772279 0.302332567749545 0.999040515394881 0.146755892550573 0.236088976264 0.0923385955393314 0.39658072614111 0.186260211281478 0.387910740217194 0.345560725079849 0.66974604036659 0.396767468657345 0.935539072612301 0.538816731888801 0.846310918219388 0.419194519054145 0.313273512991145 0.685219500679523 0.524548162706196 0.204452248988673 0.44345289375633 0.878117437008768 0.22957722004503 0.027387595968321 0.534413907211274 0.670467507559806 0.913962022401392 0.417304804315791 0.45720480917953 0.558689827332273 0.430698570096865 0.140386936953291 0.939127794932574 0.198101483285427 0.778389235492796 0.800744566367939 0.715970510849729 0.968261571833864 0.802757503231987 0.313424184685573 0.0928008102346212 0.692322616931051 0.518152548233047 0.876389146083966 0.865020245313644
        Anyway, even if numbers are same, point was it's not documented in module .pod, so might change in the future/in the past. Who knows.
        UPD: seems second example same as yours.
        It does, else it wouldn't be the Mersenne Twister.
        Which one?
        here are at least two common variants of the algorithm, differing only in the size of the Mersenne primes used. The newer and more commonly used one is the Mersenne Twister MT19937, with 32-bit word length. There is also a variant with 64-bit word length, MT19937-64, which generates a different sequence.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1054454]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (16)
As of 2014-07-24 18:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (165 votes), past polls