Re: Needing a random number generator for scripting
On Thu, 27 Sep 2001, Joey Hess wrote:
> Anthony J. Breeds-Taurima wrote:
> > <== randomize ==>
> > #!/usr/bin/perl
> > ## print a file in random order
> > while(<>) {
> > $_{$_}=0
> > }
> > foreach (keys%_) {
> > print
> > }
>
> keys is hardly random. It always outputs the keys in the same order for
> a given set of keys.
I didn't say it was _good_ I just said I used it.
<== randomize2 ==>
#!/usr/bin/perl
## print a file in random order
while(<>) {
$_{$_}=rand;
}
foreach (sort {$_{$a} <=> $_{$b}} (keys%_)) {
print
}
This is now basically the awk|sed|cut solution just in perl.
Yours Tony.
/*
* "The significant problems we face cannot be solved at the
* same level of thinking we were at when we created them."
* --Albert Einstein
*/
Reply to: