Complete.Org: Mailing Lists: Archives: discussion: April 2000:
[aclug-L] Re: Perl Random number!!
Home

[aclug-L] Re: Perl Random number!!

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: discussion@xxxxxxxxx
Subject: [aclug-L] Re: Perl Random number!!
From: John Phillips <jphillip@xxxxxxxxxxxxx>
Date: Sat, 15 Apr 2000 20:10:16 -0500 (CDT)
Reply-to: discussion@xxxxxxxxx

A random number in a set of 5 will be the same number as the
previous number 1 out five times.  A random number is not defined
as being 'different' from the previous number.  Runs of the same 
nunber are found.  When you put the 'different from the previous
number' requirement on, it's no longer a random number.
John Phillips


On Sat, 15 Apr 2000, Mohammad Islam wrote:

> Hi,
> 
> I have a question about generating random number in perl.
> 
> What do i need to do to generate a different random number each time?
> 
> Lets say I have an array called @tokens. It has five elements. I want to
> generate a random number and pick one of those elements randomly. Each
> time it has to be different than the previous one.
> 
> Say, i have the following code;
> 
> 
>  
> srand();
> 
> $myrandom = int(rand(@tokens));
> 
> with this code, i am getting some of the elements(say... the first or
> the third element in the array) more times than the others (Which is
> fine). To elaborate, if @token = (1,2,3,4,5) and i ran the above code 5
> times, i get 1 one time, 4 one time, 0 two times and 3 twice(fourth and
> fifth time i ran the program). Now what can i do here to generate a
> different random number each time i run the program? (I want it to
> generate a random number that is different from the previous random
> number it generated)
> 
> Any pointers, insights would be greatly appreciated.
> 
> Thanks.
> 
> Mohammed.
> 
> -- This is the discussion@xxxxxxxxx list.  To unsubscribe,
> visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi
> 


-- This is the discussion@xxxxxxxxx list.  To unsubscribe,
visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi


[Prev in Thread] Current Thread [Next in Thread]