Select Page

Recently, I needed to generate 4 digit random PIN number. Instead of exporting things out, making changes and doing things manually, or writing some code to do it — I decided to just use MySQL itself for the job.

UPDATE contacts SET code = concat( char(round(rand()25)+65), char(round(rand()25)+65), char(round(rand()25)+65), char(round(rand()25)+65) ) WHERE code = "";

Hopefully, you find this useful somewhere.