[Rails] Good Random Positive Integer

Tonight I needed a quick way to generate a good pseudo random number. The following statement in Ruby will generate a positive integer between 0 and the maximum integer supported on the system.

SecureRandom.random_number((2**(0.size * 8-2)-1))

Running that 10 times as a test on my system returned:

That’s all for tonight.

Sources