Helpful Information
 
 
Category: Perl Programming
Randomisation???

i need to do a randomisation of an array how do i do it?? i tried the rand() function but it returns some weird numbers with lots of decimal points....
thanks i really need help!!

If I understood you correctly this is what you want. It will print random line from @phrases array:
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
# Invoke srand; with a seed of the time and pid. If you are on a machine
# which doesn't put the pid into $$ (ie. Macintosh, Win NT, etc...), change
# this line to: srand(time ^ 22/7);

srand(time ^ $$);

# Now pluck our random phrase out of the @phrases array! But wait! This
# only returns a number.

$phrase = rand(@phrases);

# Print out the Content-type header, so the browser knows what's going on.

print "Content-type: text/htmlnn";

# Change this number into the text we want to return and print it!

print $phrases[$phrase];
[/code]

[This message has been edited by Pepe (edited November 27, 2000).]

[This message has been edited by Pepe (edited November 27, 2000).]

thanks pepe..
u have solved part of my problem...in my case i have to randomise an array of string that i have extracted from my database..what u have written in the above post only get 1 string out from the array. if i use the rand() function that u have taught me, sometimes it will get back the same string from the array again..
anyway thanks for ur help..










privacy (GDPR)