SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot Paul_M's Avatar
    Join Date
    Mar 2001
    Location
    London
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Random Number within limits

    HI

    I need to know how to generate a random number within a specified limit.

    Eg. to generate a random number between 1 and 100

    Thanx in advance

  2. #2
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Paul,

    Try the function

    RAND(100)

    Paul

  3. #3
    Happy Holidays !! Paul S's Avatar
    Join Date
    Mar 2001
    Location
    Mexico
    Posts
    1,287
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oops, my previous anwser is for MySQL, for PHP is the same but you can also use this function as

    PHP Code:
    int rand ([int min [, int max]]) 
    for more information goto http://www.php.net/manual/en/function.rand.php
    Last edited by Paul S; May 29, 2001 at 22:01.

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Don't forget to seed the random generator first with this statement:

    srand((double)microtime() * 1 000 000);

    and read the user comments to srand() about only calling this function ONCE per script.
    Last edited by 7stud; May 30, 2001 at 00:53.

  5. #5
    SitePoint Zealot Paul_M's Avatar
    Join Date
    Mar 2001
    Location
    London
    Posts
    160
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a ton


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
  •