I wanted to generate a PIN code, so I used the sprintf and rand methods.
sprintf('%04d', rand(10000)) //Fill the remaining part with 0 for 4 digits
=>"1184"
sprintf('%10d', rand(10000)) //Right-handed with a width of 10
sprintf('%-10d', rand(10000)) //Left-handed with a width of 10
=> " 7179"
Recommended Posts