PHP Echo Tutorials

Update MySQL Field With Random Number

Written by phpecho.com   

This little MySQL snippet, which I ran as a query via PHPMyAdmin, shows how you can add a bit of randomness to a number. In this case I had a column full of 1980 and wanted to randomize the last digit to mix up my birth_year column with random years within the 1980s.

UPDATE vos_members_data SET birth_year = replace(birth_year,'1980',CONCAT('198', FLOOR(RAND()*10)));

So Instead of a column like this:

1980
1980
1980
1980
1980
1980
1980
1980

You can have one that looks more like this:

1982
1981
1983
1986
1984
1989
1980
1983