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
  • 119,891
  • 44
  • 235
  • 294
Peter Penzov
  • 1,126
  • 134
  • 430
  • 808

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
  • 119,891
  • 44
  • 235
  • 294