So, cPython (2.4) has some interesting behaviour when the length of something gets near to 1<<32 (the size of an int).
r = xrange(1<<30)
assert len(r) == 1<<30
is fine, but:
r = xrange(1<<32)
assert len(r) == 1<<32
ValueError: xrange object size cannot be reported`__len__() should return 0 <= outcome
Alex's wowrange has this behaviour as well. wowrange(1<<32).l
is fine, but len(wowrange(1<<32))
is bad. I'm guessing there is some floating point behaviour (being read as negative) action going on here.
- What exactly is happening here? (this is pretty well-solved below!)
- How can I get around it? Longs?
(My specific application is random.sample(xrange(1<<32),ABUNCH))
if people want to tackle that question directly!)