Skip to content

Instantly share code, notes, and snippets.

@PhDP
Created May 22, 2014 19:01
Show Gist options
  • Save PhDP/a18f737b3f1e21651c9a to your computer and use it in GitHub Desktop.
Save PhDP/a18f737b3f1e21651c9a to your computer and use it in GitHub Desktop.
Why directional rounding is odd. Try with python2 (rounds ties away from zero, which is bad) and python3 (rounds ties to nearest even number).
from random import randint as rand
max = 10000000
sum = 0
sumR = 0
for i in range(0, max):
x = rand(1, 1000) / 2.0
sum += x
sumR += round(x)
print((sumR - sum) / max)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment