#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    singapore
    Posts
    21
    Rep Power
    0
    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!!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    71
    Rep Power
    15
    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).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    singapore
    Posts
    21
    Rep Power
    0
    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..

IMN logo majestic logo threadwatch logo seochat tools logo