Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: randfunc in Config

by BrowserUk (Patriarch)
on Jun 27, 2016 at 10:53 UTC ( [id://1166647]=note: print w/replies, xml ) Need Help??


in reply to randfunc in Config

Is there some other method besides using %Config to check that Perl uses its own drand48 function?

I would have thought the simplest test would be to seed (srand) with a known value (say 1) and test the first value that rand() returns. If it is the same PRNG you are expecting, then it will produce the same first (and sequence) of values.

That said, it does kind of lead to the question: what is it that you are testing that requires a specific PRNG in the first place?

It sounds like -- and given it is you, I'll not say it any more strongly than that -- you are testing the wrong thing. Ie. You appear to be testing for a specific implementation of a PRNG; rather than for the successful product of whatever your module that uses the PRNG is meant to produce.

What I'm getting at is: is it necessary to limit the use of your module to implementations that have one specific PRNG available?


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". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice. Not understood.

Replies are listed 'Best First'.
Re^2: randfunc in Config
by Corion (Patriarch) on Jun 27, 2016 at 10:58 UTC

    Having a unified (drand48) rand() implementation is one of the features that came in with Perl 5.20.0, so testing in a sensible way for availability of drand48 (instead of testing for 5.20.0+) is the main goal for choroba I think.

      Having a unified (drand48) rand() implementation is one of the features that came in with Perl 5.20.0, so testing in a sensible way for availability of drand48 (instead of testing for 5.20.0+)

      Besides that 5.20+ seems like a far simpler criteria to test for; even if the goal is "any perl with drand48 even if that's a linux build before 5.20"; that still suggests that he is insisting on a 48-bit PRNG, which without knowing what the module is doing, seems short-sighted.

      Ie. Why does it need to be 48-bit? How would the modules functionality be affected if I wanted to use the 32-bit MT? Or the 64-bit MT? Or even the very fast simd implementation of the 64-bit MT? What if I chose to provide a 48-bit PRNG that isn't the drand48 implementation?

      If he needs that particular implementation, then seeding to a known seed and testing the first return value will detect it, both if it is under a different name; and perhaps more importantly, fail if it has the right name but the implementation has been screwed up.

      But still the nagging in the back my head says that any algorithm that uses random numbers but needs one very specific PRNG to operate, is badly designed.

      I can see that TDD proponents would like to be able to specify they PRNG because then all their little OK/NOK tests can compare against known pre-calculated outputs; but if that is the purpose; as soon as you've detected that you have the right PRNG, all those comparisons against pre-calculated outputs become redundant.


      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". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice. Not understood.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2024-04-23 10:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found