[aclug-L] Re: Perl Random number!!
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Jeff wrote:
>
> Remember which random number it gave you and loop until it gives
> you a different one.
>
> my $lastone=undef;
> while ($you want more) {
> my $randnum = int(rand @tokens);
> while ($randnum == $lastone) {
> $randnum = int(rand @tokens);
> }
> $lastone = $randnum;
> # use $randnum
> }
>
Thanks..i will try it. One small question.. if this is a cgi script and
i want my script to remember or somehow know what the previous random
number was when it ran last time, do i need to write it to a file or is
there some magic in perl that can help me achieve this?
> By the way, you realize that $myrandom is really an index into the
> @tokens array instead of the value itself -- $myrandom =
> $tokens[int(rand @tokens)]; -- would give you the value from the
> array.
>
yea.. i am using $tokens[$myrandom] to get the value out.
Thanks for your kind reply.
Mohammed.
-- This is the discussion@xxxxxxxxx list. To unsubscribe,
visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi
|
|