0

I want to take a sample number from this defined range of numbers.

def self.ipg_amount_range
  (1..1000000000000000).to_a.sample
end

But when I load the code it takes a lot of time to load the code. Is there some way to speed up this code execution?

Yu Hao
  • 115,525
  • 42
  • 225
  • 281
Peter Penzov
  • 2,352
  • 100
  • 358
  • 675

1 Answers1

5

The to_a method takes a lot of time to generate the array, which you don't need.

Just use:

rand(1..1000000000000000)
Yu Hao
  • 115,525
  • 42
  • 225
  • 281