I tried making it utilizing exponents, but the pow()
function starts giving errors at after a certain size. I need an integer about 6 million digits long. Either that or a string of numbers works too. It can't be infinity though, because I need it for string manipulation.
Asked
Active
Viewed 194 times
0

Andrew Tsay
- 1,893
- 6
- 23
- 35
-
Wait... 6 million digits. You probably can't even keep that in memory all at once, you'll have to use disk I/O and work in parts. – Cory Kramer Sep 18 '14 at 23:44
-
1Cyber I think you can easily store 6 million characters in memory on most modern computers ... – Joran Beasley Sep 18 '14 at 23:49
-
1@Cyber: it is around ~500K: `(10**1000000).bit_length() // 8` – jfs Sep 18 '14 at 23:50
-
1integer arithmetics has unlimited precision in Python. It might be not the fastest way to handle large numbers but the result should be precise. Check that you have not used a float by accident. – jfs Sep 18 '14 at 23:58
1 Answers
3
size_of_number = 6000000
s = "".join(random.choice("0123456789") for _ in xrange(size_of_number))
doesnt work?

Joran Beasley
- 110,522
- 12
- 160
- 179
-
1`os.urandom(nbytes)` might be more efficient way to generate `nbytes` random bytes (you could [use `int.from_bytes()` to get Python `int` from the bytes](http://stackoverflow.com/a/12162190/4279)) – jfs Sep 18 '14 at 23:57