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

Re^4: Predictable random sequence

by vsespb (Hermit)
on Sep 17, 2013 at 15:10 UTC ( #1054467=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Predictable random sequence
in thread Predictable random sequence

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.


Comment on Re^4: Predictable random sequence
Select or Download Code
Re^5: Predictable random sequence
by BrowserUk (Pope) on Sep 17, 2013 at 15:32 UTC
    Anyway, even if numbers are same, point was it's not documented in module .pod, so might change in the future/in the past.

    If it does/did, it would not be a faithful implementation of the Mersenne twister.

    UPD: seems second example same as yours.

    It appears that the argument to rand is being ignored on both my windows installations but not on your linux install.

    Which is intriguing as they should be using the same perl code. I don't have an explanation for that yet.

    But, it you use it without an argument (ie. you retrieve just the 0-1 range random float and multiply it out yourself), you'll get the same results everywhere. That doesn't need to be documented because it is a fact of the design of the MT.


    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.
Re^5: Predictable random sequence
by BrowserUk (Pope) on Sep 17, 2013 at 15:50 UTC

    Hm. Intriguing. It seems that the Windows versions are doing the 'right thing'. Ie. ignoring the argument when you call rand and returning a random float 'tween 0 .. 1.

    To get the equivalent behaviour of the built-in rand where the random float is multiplied by the argument, you need to import the function irand().

    I cannot see by inspection why (or even how) you get different behaviour on linux?

    It seems it should do the same thing as the Windows install:

    sub rand { my ($self, $N) = @_; unless (ref $self) { Math::Random::MT::srand() unless defined $gen; $self = $gen; } return $self->genrand(); } sub irand { my ($self, $N) = @_; unless (ref $self) { $N = $self; Math::Random::MT::srand() unless defined $gen; $self = $gen; } return ($N || 1) * $self->genirand(); }

    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 cannot see by inspection why (or even how) you get different behaviour on linux?
      Different versions of the module?
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

        I'm looking at the code on CPAN and comparing it with my local copy and it has barely changed, and as far as I can tell there is no platform dependence that would explain why the OP is getting different results.

        In fact, beyond a single typedef and the name of a header file, I see no platform dependency at all.

        Quite how the OP gets the output he posted is beyond my understanding.


        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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (12)
As of 2014-07-22 09:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (109 votes), past polls