Oops. That should be $get = int(rand(5));

-----Original Message-----
From: Timothy Johnson [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 27, 2002 4:12 PM
To: 'Wytch'; [EMAIL PROTECTED]
Subject: RE: random word from array



The return value of rand() is a random number between 0 and the optional
argument (1 by default).

In this case there are 6 elements in the array, so we want a number between
0 and 5.  So try this variation on your code:


@tea = ("Meba", "Shaun", "Mark", "Jason", "Rick", "Dan");

$get = int(rand(6));
print $get;
$who = $tea[$get];

$affirm = "The lucky tea maker is ";
$result = $affirm.$who;
$fail = "Sorry I wasn't listening. Try again!\n";


if (defined($tea[$get])){
        print $result
}else{
        print "$fail" 
}

-----Original Message-----
From: Wytch [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 27, 2002 3:26 PM
To: [EMAIL PROTECTED]
Subject: random word from array


I decided to write a little script to help choose who will make the tea on
our gaming night [there is always an argument!]

I thought I was doing quite well but it seems I am picked on by the
[non]random script I wrote! It seems to default to the first word in the
array.

I used rand @array;

I think perhaps that I am thinking about it too simply and perhaps I need to
involve more math - but I am not good at maths [though I am willing and a
quick learner...lol] ! so can anyone point me in the right direction?

#!c:/perl/perl.exe

@tea = "Meba", "Shaun", "Mark", "Jason", "Rick", "Dan";

#below is the problem area I think - perhaps rand is not appropriate here?
#or I haven't phrased it right?
#I have looked through masses of documentation and faqs but can't find a
thing.
#Am I blind or just dim?

$get = rand @tea;
$who = $tea[$get];

$affirm = "The lucky tea maker is ";

$result = $affirm.$who;

$fail = "Sorry I wasn't listening. Try again!\n";

print "Enter y to see who will make the tea: ";
$input = <STDIN>;
chomp $input;


if ($input eq "y") {
      $a= true;
      }

if ($a) {print $result
}
else
{
 print "$fail" };





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



----------------------------------------------------------------------------
----
This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

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


--------------------------------------------------------------------------------
This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

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

Reply via email to