Mehur Mehur - 1 month ago 7
MySQL Question

Generate 6 digit random number in mysql

I want to generate random 6 digit number in mysql but sometime it generate only 5 digit.

UPDATE member SET updates = FLOOR(RAND() * 999999)

Answer

If the problem is that you are missing leading zeros, you can left pad with spaces:

UPDATE member
    SET updates = LPAD(FLOOR(RAND() * 999999.99), 6, '0');

I hope you understand that "random" means "random" and different rows can get the same value.