in reply to Need a wait to generate a 4 digit "PIN" number
Concatenate the three "bits of data" in some way (e.g. join), calculate some hash function over it (e.g. MD5 using Digest::MD5) and extract an integer from this hash (e.g. unpack). Calculate the rest modulo 10000 (perlop, look for %) and use sprintf to get a 4-digits zero-padded representation -- you're done.
Note that this does not guarantee that the combinations from 0000 to 9999 are covered fairly. Well, I actually don't know... I'm just not able/willing to demonstrate it.
Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need a wait to generate a 4 digit "PIN" number
by jaiello (Novice) on Dec 16, 2007 at 04:23 UTC | |
by ikegami (Patriarch) on Dec 16, 2007 at 05:44 UTC | |
by jaiello (Novice) on Dec 16, 2007 at 07:35 UTC | |
by ikegami (Patriarch) on Dec 16, 2007 at 15:59 UTC | |
by jaiello (Novice) on Dec 17, 2007 at 23:53 UTC | |
by lidden (Curate) on Dec 16, 2007 at 10:04 UTC |