Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^5: How do I make a random shuffle deterministic?

by Anonymous Monk
on Dec 05, 2012 at 17:46 UTC ( #1007346=note: print w/replies, xml ) Need Help??

in reply to Re^4: How do I make a random shuffle deterministic?
in thread How do I make a random shuffle deterministic?

Thanks for the tips. It is acceptable if some hosts have the same seed. Still, lessening those occurrences is a good thing. How about this:

sub seed { my $string = shift; my $seed; my @ascii = map ord, split //, $string; my $product = pop @ascii; for ( @ascii ) { $seed += $_ }; $seed = $seed * $product; srand $seed; }

Replies are listed 'Best First'.
Re^6: How do I make a random shuffle deterministic?
by LanX (Bishop) on Dec 05, 2012 at 17:53 UTC
    "rolfi" and "flori"?

    just a guess: try multiplying each ord with a different prime (by position) and do a module biggest prime <256 before adding.

    or start a new thread about efficient checksums! :)

    UPDATE: the automatic seeding is quite efficient, so why don't you determine a unique seed at installation time from a random number.

    Cheers Rolf

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1007346]
[ovedpo15]: consider the following format of strings: some_data-doesn't- matter,value. how I get the value with regex? it should be after the last comma (last string)
[Corion]: Text::CSV_XS for all your CSV file parsing needs. Other than that, what problems do you have with perlre, and capturing everything after the comma? Also, index and substr would also work.
[choroba]: my ($value) = $string =~ /.*,(.*)/
[choroba]: The .* at the beginning matches the longest possible substring, so it eats any previous commas
[choroba]: But for CSV, use appropriate modules

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2018-05-27 08:50 GMT
Find Nodes?
    Voting Booth?