Blankman Blankman - 1 year ago 123
Ruby Question

generate a random number with 7 digits

How can I produce a random number in a range from 1million to 10 million.

rand(10) works, I tried rand(1..10) and that didn't work.

Answer Source

Take your base number, 1,000,000 and add a random number from 0 up to your max - starting number:

 1_000_000 + Random.rand(10_000_000 - 1_000_000) #=> 3084592
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download