Thread: random numbers

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

    Join Date
    Jul 2000
    Posts
    12
    Rep Power
    0
    I need to generate a random number between 1 and (a number that changes daily). mysql has the RAND command but it only generates a number between 0 and 1, as far as I know. We are using roxen as our webserver, and it has a RANDOM tag built in... but if you wanted a random number between, say, 1 and 5, you have to list the numbers 1, 2, 3, 4, and 5... this is inconvenient at best. does roxen or mysql have a way to generate a random number BETWEEN 2 numbers? like (random) (1, 200) (/random) or something similar?

    Thanks for any help..
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4476
    Most rand functions only return a value between 0 and 1. if you want a value between 1 and 100, then you multiply the output of the rand() function by 100 and add 1. (1 + rand() * 100). if you want a number between 100 and 200, (100 + rand() * 200). I think you can do this all in the mysql statement or in whatever scripting language you are using.

    ---John Holmes...
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    12
    Rep Power
    0
    That's actually exactly what I thought of doing a few hours after I had posted the message. But thank you for the help.

Similar Threads

  1. generating random numbers of a fixed length
    By alexh in forum PHP Development
    Replies: 3
    Last Post: June 24th, 2004, 03:22 AM
  2. generating random numbers in a range
    By infamous41md in forum C Programming
    Replies: 3
    Last Post: August 31st, 2003, 06:35 PM
  3. 5 Unique random numbers 0 to 11
    By steve8557 in forum PHP Development
    Replies: 16
    Last Post: July 17th, 2002, 07:26 PM
  4. concept on random numbers
    By kojr in forum Perl Programming
    Replies: 2
    Last Post: January 5th, 2002, 04:42 PM
  5. Working with random numbers.
    By GraphX in forum PHP Development
    Replies: 4
    Last Post: December 15th, 2001, 04:59 PM

IMN logo majestic logo threadwatch logo seochat tools logo