Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an error in Python 3's random.SystemRandom.randint, or am I using in incorrectly?

Tags:

python

random

>>> import random
>>> random.SystemRandom.randint(0, 10)
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    random.SystemRandom.randint(0, 10)
TypeError: randint() missing 1 required positional argument: 'b'

SystemRandom is supposed to give random numbers though os.urandom, randint works like normal randrange:

>>> print(random.SystemRandom.randint.__doc__)
Return random integer in range [a, b], including both end points.

In IDLE a little popup suggestion appears when I type it it saying

`random.SystemRandom.randint(self, a, b)`

I think this is the cause. I'm not very good at using classes and understanding how they work, but the first argument seems to be being passed as self, when it should be a. I never really understand why self is used when it isn't even a keyword, and how it's supposed to all just work, but it generally does.

Am I doing this wrong, or should I report this to the Python Foundation whenever one is supposed to do such things?

like image 870
Henrik Oldcorn Avatar asked Jun 07 '15 23:06

Henrik Oldcorn


1 Answers

When the error is "TypeError: randint() missing 1 required positional argument: 'b'" it's because the person writing the code probably mixed up their

random.randint()

and their

random.choice()

Hope I helped :D

like image 57
GingerCat_error404 Avatar answered Sep 17 '22 05:09

GingerCat_error404