Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How do I make a random shuffle deterministic?

by LanX (Canon)
on Dec 05, 2012 at 16:25 UTC ( #1007320=note: print w/ replies, xml ) Need Help??


in reply to How do I make a random shuffle deterministic?

my best guess is:

Initialize an array of random indices only once for each host.

And use a host identifier (like hostname or ip) as seed in srand

UPDATE:

according to the docs (from perldoc -f srand) it's deterministic

You can call srand($seed) with the same $seed to reproduce the same sequence from rand(), but this is usually reserved for generating predictable results for testing or debugging. Otherwise, donít call srand() more than once in your program.

UPDATE: works fine:

DB<100> srand 42 => 1 DB<101> rand => "0.744525000061007" DB<102> rand => "0.342701478718908" DB<103> rand => "0.111085282444161" DB<104> rand => "0.422338957988309" DB<105> srand 42 => 1 DB<106> rand => "0.744525000061007" DB<107> rand => "0.342701478718908" DB<108> rand => "0.111085282444161"

Cheers Rolf


Comment on Re: How do I make a random shuffle deterministic?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (12)
As of 2014-08-29 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (280 votes), past polls