Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random.SystemRandom(seed) documentation issue #73347

Closed
garyemiller mannequin opened this issue Jan 4, 2017 · 8 comments
Closed

random.SystemRandom(seed) documentation issue #73347

garyemiller mannequin opened this issue Jan 4, 2017 · 8 comments
Assignees
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@garyemiller
Copy link
Mannequin

garyemiller mannequin commented Jan 4, 2017

BPO 29161
Nosy @rhettinger, @garyemiller

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/rhettinger'
closed_at = <Date 2017-01-05.02:00:55.945>
created_at = <Date 2017-01-04.23:44:44.527>
labels = ['3.7', 'invalid', 'type-bug', 'library']
title = 'random.SystemRandom(seed) documentation issue'
updated_at = <Date 2017-01-05.02:43:15.956>
user = 'https://github.com/garyemiller'

bugs.python.org fields:

activity = <Date 2017-01-05.02:43:15.956>
actor = 'gem'
assignee = 'rhettinger'
closed = True
closed_date = <Date 2017-01-05.02:00:55.945>
closer = 'rhettinger'
components = ['Library (Lib)']
creation = <Date 2017-01-04.23:44:44.527>
creator = 'gem'
dependencies = []
files = []
hgrepos = []
issue_num = 29161
keywords = []
message_count = 8.0
messages = ['284678', '284680', '284681', '284683', '284686', '284688', '284690', '284693']
nosy_count = 2.0
nosy_names = ['rhettinger', 'gem']
pr_nums = []
priority = 'low'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue29161'
versions = ['Python 2.7', 'Python 3.3', 'Python 3.4', 'Python 3.5', 'Python 3.6', 'Python 3.7']

@garyemiller
Copy link
Mannequin Author

garyemiller mannequin commented Jan 4, 2017

The man page for random.SystemRandom([seed]]) fails to mention that the parameter 'seed' is never used. This should be prominent in the documentation. I have found several cases where a seed was provided to SystemRandom().

https://docs.python.org/2.7/library/random.html?highlight=systemrandom

Present in all versions of Python docs that I could find.

@garyemiller garyemiller mannequin added 3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Jan 4, 2017
@rhettinger rhettinger self-assigned this Jan 5, 2017
@rhettinger
Copy link
Contributor

From the docs at https://docs.python.org/3/library/random.html#alternative-generator :

"""
class random.SystemRandom([seed])
Class that uses the os.urandom() function for generating random numbers from sources provided by the operating system. Not available on all systems. Does not rely on software state, and sequences are not reproducible. Accordingly, the seed() method has no effect and is ignored. The getstate() and setstate() methods raise NotImplementedError if called.
"""

What is it that you think needs to be added or changed?

@garyemiller
Copy link
Mannequin Author

garyemiller mannequin commented Jan 5, 2017

I would change:

"Accordingly, the seed() method has no effect and is ignored."

To:

"Accordingly, the optional seed parameter and the seed() method have no effect and are ignored."

It was not obvious to me that the seed paramrter got passed to the seed() method and was then ignored. After all, why have an ignored parameter that is not plainly documented as ignored.

@rhettinger
Copy link
Contributor

why have an ignored parameter that is not plainly documented as ignored.

Because it improves the substitutability of one RNG for another (i.e. the same reason that we even have a seed() method).

@garyemiller
Copy link
Mannequin Author

garyemiller mannequin commented Jan 5, 2017

> why have an ignored parameter that is not plainly documented as ignored.

Because it improves the substitutability of one RNG for another (i.e. the same reason that we even have a seed() method).

I understand why it the parameter it there. I think the parameter should stay there. I am all for orthogonal functions. It just needs to be documented that the parameter is ignored by SystemRandom().

Programmers are being misled by the online documentation and adding a seed parameter when it does nothing.

I should not have to read the library code to find out that a parameter is ignored.

@garyemiller
Copy link
Mannequin Author

garyemiller mannequin commented Jan 5, 2017

Is there a better place to submit documentation problems to? After my programming team spends a lot of valuable time figuring what the Python doc failed to mention I would like this knowledge to be put to good use by others. Paying it forward if you will.

@rhettinger
Copy link
Contributor

Thank you for the submission. I respect what you're trying to do, but disagree that there is any issue here. The docs are clear that System Random uses os.urandom() for creating random numbers, that there is not state, that sequences aren't reproducible, and that seed method has no effect and is ignored. Also, the square brackets on the seed argument is our traditional way of saying that an argument is optional.

Apologies, but I'm going to close this. IMO, the proposed wording is less clear and doesn't really help if someone is already misunderstanding what SystemRandom is all about and is imagining that the "seed" argument has some effect when the seed method is documented as being ignored.

@garyemiller
Copy link
Mannequin Author

garyemiller mannequin commented Jan 5, 2017

The docs are clear that System Random uses os.urandom() for creating random numbers, that there is not state, that sequences aren't reproducible, and that seed method has no effect and is ignored.

Agreed, but not relevant. I have anecdotal proof that the docs are not clear to a number of talented Python programmers that the seed parameter is not used. Or that the seed parameter is passed to the seed() method (and thus unused).

Disappointing...

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant