ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 03 Feb 2018 19:28:10 +0100Uniform random choice of integerhttps://ask.sagemath.org/question/40960/uniform-random-choice-of-integer/I want to perform some statistical sampling and to do this I need to uniformly randomly choose an integer from [0, N) where $N \approx 10^{50}$. It appears that there are several plausible ways to do this in Sage:
1) randint(0, N-1)
However, the standard Python random library appears to have some non-uniformity, for example [see this ticket](https://bugs.python.org/issue9025).
2) import numpy; numpy.random.randint(0, N)
However, since N is so large, this raises
ValueError: high is out of bounds for int64
3) ZZ.random_element(0, N)
> Do either of the issues that methods 1) and 2) suffer from apply to method 3)? That is, is 3) the correct way to integers uniformly at random?Mark BellSat, 03 Feb 2018 19:28:10 +0100https://ask.sagemath.org/question/40960/