One of my friends asked me “How do I create a 10 digit random number?”

MySQL supports RAND() system function which can produce a random number between 0 and 1 with 16 digits as the decimal part.

An example for a random value can be obtained using

SELECT RAND() as random_number;

The result is

random_number
-------------------
0.7638836063108254

Note that every time you run this code, you will get a different number.

Now to get 10 digit whole number, multiple it by 10000000000 and omit the decimal part by converting the result into UNSIGNED number

SELECT CAST(rand()*10000000000 as UNSIGNED) as random_number

The result is

random_number
-------------------
5176665713

This can be modified easily to get other number with fixed digits. For example if you want a random 4 digit number, you can use

SELECT CAST(rand()*10000 as UNSIGNED) as random_number

The result is

random_number
-------------------
5278

You can parameterize this to work for any number of fixed digits you want