Example tutorial for Python random () function

Source: Internet
Author: User

The following small series for everyone to bring a python random function small composition think very good, now share to everyone, also for everyone to do a reference. Follow the small series together to see it.

Describe

The random () method returns a randomly generated real number that is within the range of [0,1].

Grammar

The following is the syntax for the random () method:

Import Randomrandom.random ()

Note: The random () is not directly accessible, you need to import the random module, and then call the method through the random static object.

return value

Returns a randomly generated real number that is within the range of [0,1].

Instance

The following shows an example of using the random () method:

#!/usr/bin/pythonimport random# generates the first random number print "random ():", Random.random () # Generates a second random number print "random ():", Random.random ( )

When the above instance is run, the output is:

Random ():  0.281954791393random ():  0.309090465205

"Recommended"

1. A detailed description of the mathematical and random numbers in the Python standard library (math package, random package)

2. Share a tutorial on how to generate random numbers in Python module

3. Share an example tutorial on random (randomly generated numbers) in Python

4. Share Python Random example of a method that generates n random numbers that are not duplicated in a range

5. Python Random Module (get random number) common methods and use examples

6. Python Random Module Common methods

7. Python Module Learning: Random number generation

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.