On Monday, April 29, 2002, at 02:34 , Nikola Janceski wrote:
> what about?
>
> my @numbers = 1..100;
> while($#numbers >= 0) {
> my $index = rand $numofques;
> my $element = $numbers[$index];
> $numbers[$index] = pop @numbers; # replace the number we used with
> the
> last e
On Monday, April 29, 2002, at 02:03 , Bob Showalter wrote:
[..]
http://www.wetware.com/drieux/CS/lang/Perl/Beginners/BenchMarks/randTest.txt
has been updated to take in more data...
>
> splice() will be slower as the size of the array grows. If I take
> your benchmark and change to array from 1
printf "\n"
Wouldn't this run faster?
> -Original Message-
> From: drieux [mailto:[EMAIL PROTECTED]]
> Sent: Monday, April 29, 2002 5:27 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Scripts picks random elements from array , but it repeats
> som etimes
>
On Monday, April 29, 2002, at 02:03 , Bob Showalter wrote:
> splice() will be slower as the size of the array grows. If I take
> your benchmark and change to array from 1..100 to 1..1, I get
> the following results for 100 iterations (on an old Pentium 266):
>
> Benchmark: timing 100 iterati
> -Original Message-
> From: drieux [mailto:[EMAIL PROTECTED]]
> Sent: Monday, April 29, 2002 4:51 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Scripts picks random elements from array , but it repeats
> som etimes
>
>
>
> On Monday, April 29, 2002,
On Monday, April 29, 2002, at 01:03 , Bob Showalter wrote:
> May I suggest a modification of the algorithm that avoids this
> problem:
>
>1. generate a random index from 1 to (number of remaining elements)
>2. use the element at that index
>3. move the last element into the index gen
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]
> Sent: Monday, April 29, 2002 3:18 PM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: RE: Scripts picks random elements from array , but it repeats
> som etimes
>
>
> H
Here is one option:
#!perl -w
my @numbers = qw( 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 );
my $numofques = scalar(@numbers);
my @MySeen = ();
while($numofques > 0) {
$index = rand @numbers;
next if ( defined$MySeen[$index] );
$element = $numbers[$index];
printf "
> -Original Message-
> From: FLAHERTY, JIM-CONT [mailto:[EMAIL PROTECTED]]
> Sent: Monday, April 29, 2002 2:58 PM
> To: Beginners (E-mail)
> Subject: FW: Scripts picks random elements from array , but it repeats
> som etimes
>
>
>
> Hello , My script picks out random elements from an a