MySQL rand function

If you need to add some random number to some of the mysql columns then here it goes…

UPDATE tableSET column = FLOOR( 1 + RAND( ) *100 )

The last number (100) means you are about to add any value until 100. So 99, 1, 5, 33, 45…any between 1 and 100.
If you put 10 instead of 100 then you will get between 1 and 10 (2, 5, 6).

Returns a random floating-point value v in the range 0 <= v < 1.0.

RAND

That’s it.

Leave a Reply

Your email address will not be published. Required fields are marked *