Thanks Janek and Japhy and Drieux for all the help on this!

I've yet to look at this Tie::Pick, but will.

In the meantime, I've gone with the Japhy solution, 

   $element = @things[rand @things];

....because it was the simplest (and works).

I didn't quite see why you would have to do a +1 on the following:

   my $RandomScript = $Scripts[int(rand($#Scripts + 1))];

because isn't the first element of an array (eg @array) $array[0]
anyway? Such that you'd want the numbers 0-3 for a 4-element array
rather than 1-4? (unless rand only works with numbers greater than zero
and, in Japhy's solution, is doing this implicitly?)

Still, grateful to know I can skip the srand; line. When I started
this, the first random seeding code I came across was even more typing:

   srand(time() ^ ($$ + ($$ << 15)) );

Well, that worked, too, but...

Anyway, again, many thanks for all,

Rohesia
 
--- Janek Schleicher <[EMAIL PROTECTED]> wrote:
> Rohesia Hamilton Metcalfe wrote at Thu, 30 May 2002 17:28:45 +0200:
> 
> > #make array of cgi-scripts:
> > @Scripts=("f-aaaa.cgi", "f-bbbbbb.cgi", "f-cccc.cgi", "f-dddd.cgi",
> "f-eeeeee.cgi",
> > "f-ffffff.cgi");
> > 
> > # pick one at random
> > srand;
> > $RandomScript = $Scripts[int(rand(@Scripts))];
> > 
> 
> I agree to Drieux that such a random selection looks strange.
> I always feel nervous when i see Jeff's solution.
> Not because of the underlying context what let's a floating value
> becomes an int,
> but $element = $things[rand @things] hides the real information.
> And there's double code (things), what is a real crime :-))
> 
> Let's look at an existing module:
> 
> use Tie::Pick;
> tie my $randomScript => Tie::Pick => @scripts;
> 
> There's a disadventage, too.
> Tie::Pick removes the element chosen,
> but when it doesn't play a role or is even wanted,
> I'd suggest the above solution.
> Otherwise I'd prefer Jeff's solution.
> 
> Greetings,
> Janek
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 


=====
Rohesia Hamilton Metcalfe

__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to