Here is a simple python snippet which generates 100 random numbers between 0 and 1, sum it, shuffle it, sum it and so on...
import random
rands=[]
for i in range(0,100):
rands.append(random.uniform(0,1))
print(sum(rands))
random.shuffle(rands)
print(sum(rands))
random.shuffle(rands)
print(sum(rands))
random.shuffle(rands)
print(sum(rands))
When I run the code on python3 it generates different output in different print
statement after shuffling the array. I understand that the way the floating point numbers are stored in memory, there will be some loss in the precision.
But when I run the code in python2, it returns the same output in every print
statement.
Can someone help me understand why?