Created
February 10, 2017 22:23
-
-
Save Supernats/6af61521064c69ac9fab99356e27331c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'securerandom' | |
def secure_random_test(max = 1_000_000) | |
ratio = (0...max).map do | |
SecureRandom.random_number(max) | |
end.uniq.count.to_f/max.to_f | |
(ratio - (1 - 1/Math::E)).abs | |
end | |
puts "SecureRandom: #{secure_random_test}" | |
def rand_test(max = 1_000_000) | |
ratio = (0...max).map do | |
rand(max) | |
end.uniq.count.to_f/max.to_f | |
(ratio - (1 - 1/Math::E)).abs | |
end | |
puts "rand: #{rand_test}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment