8000 Consider a faster alternative algorithm for random.shuffle() · Issue #108598 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

Consider a faster alternative algorithm for random.shuffle() #108598

@d-rideout

Description

@d-rideout

The documentation for the shuffle() function in the random module expresses concern that, for sequences of length larger than 2080, the shuffle() function is not able to produce all permutations of the sequence. While true, I find the emphasis on the finite period of the Mersenne Twister random number generator misleading, since the generator is only called n-1 times for a sequence of length n. The real issue is that any algorithm based on a sequence of calls to a pseudorandom number generator will not be able to generate more permutations than the generator has internal states.

(I also wonder how large of a sequence can be sent to shuffle() in practice, to be guaranteed a uniform distribution over permutations. Is 2079 small enough? 2078? Might there be a check for this?)

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsDocumentation in the Doc dir

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0