generate 6 digit random number ruby 1

generate 6 digit random number ruby

10.times.map{rand(10)}.join # => "3401487670"

Here is what the above code is Doing:
1. We’re calling the times method on the Fixnum 10.
2. We’re passing a block to the times method.
3. The block is calling the rand method on the Fixnum 10.
4. The rand method is returning a random number between 0 and 9.
5. The block is calling the join method on the array of random numbers.
6. The join method is returning a string of the random numbers.

Similar Posts