1

I'd like to pick a random number out of a huge number.

count is 4.725533031549649e+152

What should I do?

Numpy.random.randint is said to be only up to int64.

static const
  • 953
  • 4
  • 16
규링링
  • 29
  • 5
  • 2
    You mean a random digit? Or a number in the range? For the former this is may have your answer : https://stackoverflow.com/questions/10012534/how-to-generate-a-big-random-number-in-python – kabanus Jul 11 '19 at 13:35
  • I'd like to get one number from 0 to 4.725533031549649e+152 with all the same odds. – 규링링 Jul 11 '19 at 13:41
  • `import random; random.randint(0, 4725533031549649*10**152)` works fine for me – Giacomo Alzetta Jul 11 '19 at 13:42

1 Answers1

2

You can use random library.

import random
random.randrange(0, 4.725533031549649e+152)

>>> random.randrange(0, 4.725533031549649e+152)
169751096079061489415033502439315971761176373224764849829689981514727862542449749467855540992801413306200508657378631847139186549408966200866106110063885
>>> random.randrange(0, 4.725533031549649e+152)
332802078707358741701843812789346557544950682259596048311950328489197340606292985345468995905214666895030416962534136208301912797321798957162526303349975
>>> random.randrange(0, 4.725533031549649e+152)
195068584125198082963968400124527145219707541804769322353310527845126940493999253420325583765283625874685614529038994101415937997041514293267317713485347

Keep in mind that this generates pseudo-random numbers. Which are not "totally random" from a mathematical perspective.

Eduard Voiculescu
  • 141
  • 1
  • 3
  • 14