SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    E-business guru Eirik's Avatar
    Join Date
    Nov 2000
    Location
    Oslo, Norway
    Posts
    413
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Generate random number

    Hi,

    How do I generate a whole random number between two given values using PHP. T think the function gmp_random() should do something like this, but I don't understand how it works.

    Thanks in advance !
    Sincerely,

    Eirik Johansen
    Netmaking AS

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

    See:

    http://www.php.net/manual/en/function.mt-rand.php

    mt_srand ((double) microtime() * 1000000); //Only use this once per script
    $randval = mt_rand(5, 15);
    Last edited by 7stud; Jun 1, 2001 at 09:13.

  3. #3
    SitePoint Evangelist
    Join Date
    Oct 2000
    Posts
    430
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you looking for: rand(firstvalue, secondvalue); ???

    or something more complex???

  4. #4
    E-business guru Eirik's Avatar
    Join Date
    Nov 2000
    Location
    Oslo, Norway
    Posts
    413
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys! mt_rand() did the trick!
    Sincerely,

    Eirik Johansen
    Netmaking AS


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
  •