DEV Community

Khalil Gharbaoui
Khalil Gharbaoui

Posted on

Answer: How do I generate a random 10 digit number in ruby?

('%010d' % rand(0..9999999999)).to_s

or

"#{'%010d' % rand(0..9999999999)}"

Top comments (1)

Collapse
 
gvpmahesh profile image
vamsi pavan mahesh gunturu

Hi Khalil, can you please explain what's going on in the snippet you have written