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.randrange don't return correct value for big number #44199

Closed
mft mannequin opened this issue Nov 5, 2006 · 4 comments
Closed

random.randrange don't return correct value for big number #44199

mft mannequin opened this issue Nov 5, 2006 · 4 comments
Assignees
Labels
stdlib Python modules in the Lib dir

Comments

@mft
Copy link
Mannequin

mft mannequin commented Nov 5, 2006

BPO 1590891
Nosy @arigo, @rhettinger, @josiahcarlson
Files
  • randrange1.diff: Proposed fix
  • 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 2006-12-20.06:43:10.000>
    created_at = <Date 2006-11-05.16:54:05.000>
    labels = ['library']
    title = "random.randrange don't return correct value for big number"
    updated_at = <Date 2006-12-20.06:43:10.000>
    user = 'https://bugs.python.org/mft'

    bugs.python.org fields:

    activity = <Date 2006-12-20.06:43:10.000>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2006-11-05.16:54:05.000>
    creator = 'mft'
    dependencies = []
    files = ['2207']
    hgrepos = []
    issue_num = 1590891
    keywords = []
    message_count = 4.0
    messages = ['30457', '30458', '30459', '30460']
    nosy_count = 4.0
    nosy_names = ['arigo', 'rhettinger', 'josiahcarlson', 'mft']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1590891'
    versions = []

    @mft
    Copy link
    Mannequin Author

    mft mannequin commented Nov 5, 2006

    Python 2.4.3 (#1, Oct  3 2006, 00:36:06)
    [GCC 4.1.1 (Gentoo 4.1.1-r1)] on linux2
    Type "help", "copyright", "credits" or "license" for
    more information.
    >>> import random
    >>> random.randrange(1000000000000,
    -100000000000000000000, -200)
    267471051174796896L

    Obviously, the result is not in the specified range;
    1000000000000 < 267471051174796896,
    -100000000000000000000 < 267471051174796896
    and
    (267471051174796896 - 1000000000000) % (-200) != 0.

    I'm using 2.3.5 and 2.4.3, and their behaviors are
    identical.
    I haven't checked about 2.5.

    @mft mft mannequin closed this as completed Nov 5, 2006
    @mft mft mannequin assigned rhettinger Nov 5, 2006
    @mft mft mannequin added the stdlib Python modules in the Lib dir label Nov 5, 2006
    @mft mft mannequin closed this as completed Nov 5, 2006
    @mft mft mannequin assigned rhettinger Nov 5, 2006
    @mft mft mannequin added the stdlib Python modules in the Lib dir label Nov 5, 2006
    @josiahcarlson
    Copy link
    Mannequin

    josiahcarlson mannequin commented Nov 8, 2006

    Logged In: YES
    user_id=341410

    2.5 has the same behavior.

    One workaround (until it gets fixed) is to do the following...

    def myrandrange(start, stop, step):
        return start + random.randrange((stop-start)//step)*step

    random.randrange should change to do some variant of the
    above, given sane start, stop, step arguments.

    @arigo
    Copy link
    Mannequin

    arigo mannequin commented Nov 8, 2006

    Logged In: YES
    user_id=4771

    Oups. If the interval is very large, the step is
    ignored. Patch attached...

    @rhettinger
    Copy link
    Contributor

    Thanks for the report.

    Fixed in revision 53099.

    @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
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant