In
WW1.x (years ago) I think the key was a number, and so this method of
seeding the random generator would make sense. Now, however, the key is
a character string, so this won't work (when used as a number, that
string will be interpreted as zero, and so no matter what the key is,
your seed will be the same).
In order to make this work, you would need to convert the key to a
number in some way. There are many possible approaches. Here's one:
$seed = 0; foreach $c (split(//,$inputs_ref->{key})) {$seed += ord($c)} SRAND($seed);
This turns each character into its ASCII character number, and
adds up the results. Not particularly sophisticated, but it should get
you a different number for most seeds.
Davide
<| Post or View Comments |>
|