Skip to content

Instantly share code, notes, and snippets.

@pgte
Created August 2, 2011 11:10
Show Gist options
  • Save pgte/1120013 to your computer and use it in GitHub Desktop.
Save pgte/1120013 to your computer and use it in GitHub Desktop.
rand test
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