To make a random integer from 60 to 120, you need to do a bit of arithmetic with the results of RAND() , which gives only floating point values:
SELECT FLOOR(60 + RAND() * 61);
So what is going on here:
RAND() will 0.847269199 value similar to 0.847269199 . We multiply this by 61, which gives us the value 51.83615194. Add 60, as this is your offset above zero (111.83615194). FLOOR() rounds everything to the nearest integer. Finally, you have 111.
To do this over several thousand existing lines:
UPDATE table SET randcolumn = FLOOR(60 + RAND() * 61) WHERE (<some condition if necessary>);
See MySQL docs on RAND() more details.
Note I think I have arithmetic right, but if you get values ββof 59 or 121 outside the expected range, change +60 accordingly up or down.
Michael berkowski
source share