Message246336
I suppose the simplest "fix" would be to replace relevant instances of
int(random() * N)
with
min(int(random() * N), N-1)
That would be robust against many kinds of arithmetic quirks, and ensure that platforms with and without such quirks would, if forced to the same internal random state, yield the same result when random() happens to return 1. - 2.**-53.
Victor, what - precisely - do you have in mind with "only use integers"? The current method was used because it's simple, efficient, and obvious. Python 3.4.3 appears to (usually) use a different method, though, relying on C code to generate random bytes without going through floats. |
|
Date |
User |
Action |
Args |
2015-07-05 19:42:13 | tim.peters | set | recipients:
+ tim.peters, rhettinger, mark.dickinson, vstinner, steven.daprano, r.david.murray, skrah, serhiy.storchaka, Serge Anuchin |
2015-07-05 19:42:13 | tim.peters | set | messageid: <1436125333.74.0.0325733386922.issue24567@psf.upfronthosting.co.za> |
2015-07-05 19:42:13 | tim.peters | link | issue24567 messages |
2015-07-05 19:42:13 | tim.peters | create | |
|