Tips for distinguishing between randrange () and uniform () in Python

Source: Internet
Author: User
From the function signature we can know:

In [7]: Random.randrange? Signature:random.randrange (Start, Stop=none, step=1, _int=<type ' int ';, _maxwidth=9007199254740992l) docstring : Choose a random item from range (Start, stop[, step]). This fixes the problem with Randint () which includes theendpoint; In Python, this is usually don't what want. File:      /usr/lib/python2.7/random.pytype:      Instancemethodin [8]: Random.uniform? Signature:random.uniform (A, b) docstring:get a random number in the range [A, b] or [A, b] depending on rounding. File:      /usr/lib/python2.7/random.pytype:      instancemethod

Randrange is randomly selected from range (Start, stop[, Step), and the generated must be int;
Uniform is a random number generated from [A, b] or [A, b], and a float is generated;
These two usage scenarios are different.

"Recommended"

1. Special recommendation : "PHP Programmer Toolkit" V0.1 version download

2. Python Free video tutorial

3. python Foundation Uniform ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.