CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Multiple random

 



postmanpat
newbie

Jun 26, 2001, 6:01 AM

Post #1 of 2 (329 views)
Multiple random Can't Post

I am trying to mix randomly two arrays. Works ok when I call the subroutine once. But when I try and call it a second time I get the same result. I really dont understand. Anyway heres the sub...

sub randy {
#randomizes and mixes the two strings

my $cou = $#TEMPHOLD;
my @ere = @PHRASES;


my @old = @ere;
srand;


while (@old) {
push(@new,splice(@old,rand @old,1));
}

@ere = @new;

my @rer = @TEMPHOLD;
my @ttt;
while ($cou >-1) {
unshift (@ttt,"@rer[$cou]");
unshift (@ttt,"@ere[$cou]");
$cou = ($cou - 1);
}

#randomizes and mixes the two strings
}

Has anyone else had the problem?



japhy
Enthusiast

Jun 26, 2001, 9:01 AM

Post #2 of 2 (325 views)
Re: Multiple random [In reply to] Can't Post

Don't call srand(). There's no need to, and it's probably the cause of your problems.

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives