[aclug-L] Perl Random number!!
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
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
- [aclug-L] Perl Random number!!,
Mohammad Islam <=
|
|