Blankman Blankman - 12 days ago 5x
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.


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