SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: random #?

  1. #1
    SitePoint Member
    Join Date
    Jun 2000
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know this is simple, but how would I set a variable to a random number between 0 and count($array) ?

    Thanks,

    -Matt

    ------------------
    -----
    ComicalPics.com

  2. #2
    SitePoint Member
    Join Date
    Jul 2000
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could use the mt_rand() PHP function:

    int mt_rand( [int min] , [int max] );

    For example:

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">code/font><HR><pre>// create a random number between 0 and 10
    $array = array (1,2,3,4,5,6,7,8,9,10);
    $random_number = mt_rand (0, count($array));[/code]

    ------------------
    Antti
    Huotari.com/antti/
    LinuxWebDevNews.com


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •