Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How do I make a random shuffle deterministic?

by kennethk (Monsignor)
on Dec 05, 2012 at 16:30 UTC ( #1007327=note: print w/ replies, xml ) Need Help??


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

Rigging the shuffle to be identical on a given host is easy -- simply feed a fixed seed to srand before your first call to rand.

This makes variation between hosts easy by simply choosing a host-specific property as your seed -- perhaps a mangled hardware address?

#!/usr/bin/perl -w use strict; use 5.10.0; my ($eth) = `ifconfig` =~ /HWaddr (\S+)/; $eth =~ s/\W//g; { no warnings 'portable'; srand hex $eth; } say rand for 1 .. 10;

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


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://1007327]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2014-09-19 02:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls