ch 28, 2002 3:26 AM
To: [EMAIL PROTECTED]
Subject: Re: random word from array
"Randal L. Schwartz" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> That's correct, but if you have a very very very old Perl, you'll need
> to add
"James Taylor" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Hrm, try this:
>
> @tea = "Meba", "Shaun", "Mark", "Jason", "Rick", "Dan";
> srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
> print "$tea[rand(5)]\n";
Wow - I would love to say I understand th
"John W. Krahn" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Wytch wrote:
<<>>
> If you had warnings enabled Perl would have caught this for tou.
But I would have been none the wiser still! You have to understand that I
only started Perl two nights ago and
"Randal L. Schwartz" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> That's correct, but if you have a very very very old Perl, you'll need
> to add "srand;" at the beginning of your program. Do it just once,
> though.
That was one of the first things I tried
> The problem is not the rand(). The problem was the user didn't put
> parentheses around the elements of the array assignment.
>
> @array = ("This", "That", "Those");
> print $array[rand @array];
Ah ha! those curly brackets have a lot to answer for lol! I can't believe it
was something so
"Timothy Johnson" <[EMAIL PROTECTED]> wrote in message
C0FD5BECE2F0C84EAA97D7300A500D50025811D3@SMILEY">news:C0FD5BECE2F0C84EAA97D7300A500D50025811D3@SMILEY...
>
> The return value of rand() is a random number between 0 and the optional
> argument (1 by default).
>
> In this case there are 6 elem
On Mar 27, Timothy Johnson said:
>Oops. That should be $get = int(rand(5));
No. That would give you a number between 0 and 4.
The problem is not the rand(). The problem was the user didn't put
parentheses around the elements of the array assignment.
@array = ("This", "That", "Those");
pr
Wytch wrote:
>
> 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
> "Wytch" == Wytch <[EMAIL PROTECTED]> writes:
Wytch> I thought I was doing quite well but it seems I am picked on by the
Wytch> [non]random script I wrote! It seems to default to the first word in the
Wytch> array.
Wytch> I used rand @array;
Wytch> I think perhaps that I am thinking about
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
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
Hrm, try this:
@tea = "Meba", "Shaun", "Mark", "Jason", "Rick", "Dan";
srand (time ^ $$ ^ unpack "%L*", `ps axww | gzip`);
print "$tea[rand(5)]\n";
On Wednesday 27 March 2002 03:25 pm, you wrote:
> I decided to write a little script to help choose who will make the tea on
> our gaming night [t
12 matches
Mail list logo