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.
把你的基数,1,000,000,并添加一个从0到你的最大起始数的随机数:
1_000_000 + Random.rand(10_000_000 - 1_000_000) #=> 3084592
这是一个实例方法:
puts Random.new.rand(1_000_000..10_000_000-1)
This will generate a random number between 1,000,000 and 9,999,999.
rand(10_000_000-1_000_000)+1_000_000
This works in 1.8.7 without any gems(backports, etc).
链接地址: http://www.djcxy.com/p/95442.html上一篇: 选择/更新或多个选择之间的SQL Server死锁
下一篇: 生成一个7位数的随机数