Created
August 2, 2011 11:10
-
-
Save pgte/1120013 to your computer and use it in GitHub Desktop.
rand test
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
1.upto 1000 do |exp| | |
frequencies = {} | |
1.upto 5000 do |i| | |
number = rand(16); | |
frequency = (frequencies[number] || 0) + 1 | |
frequencies[number] = frequency | |
end | |
squared_sum = (0..15).map {|number| frequencies[number] * frequencies[number] }.reduce(0) {|mem, freq| mem + freq } | |
a = (16.0 / 5000.0) * squared_sum | |
x = a - 5000 | |
puts "TEST FAILED!" if x <= 1.03 || x >= 57.4 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment