This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tim.peters
Recipients Serge Anuchin, mark.dickinson, r.david.murray, rhettinger, serhiy.storchaka, skrah, steven.daprano, tim.peters, vstinner
Date 2015-07-05.19:42:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1436125333.74.0.0325733386922.issue24567@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-07-05 19:42:13tim.peterssetrecipients: + tim.peters, rhettinger, mark.dickinson, vstinner, steven.daprano, r.david.murray, skrah, serhiy.storchaka, Serge Anuchin
2015-07-05 19:42:13tim.peterssetmessageid: <1436125333.74.0.0325733386922.issue24567@psf.upfronthosting.co.za>
2015-07-05 19:42:13tim.peterslinkissue24567 messages
2015-07-05 19:42:13tim.peterscreate