|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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... |
|
#3
|
|||
|
|||
|
That's actually exactly what I thought of doing a few hours after I had posted the message. But thank you for the help.
|
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > random numbers |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|