Example tutorial of Python random() function

零下一度
Release: 2017-05-20 14:50:53
Original
2615 people have browsed it

The following editor will bring you an article about python's random function. I think it is quite good. I will share it with you now and give it as a reference. Let’s follow the editor and take a look.

Description

random() method returns a randomly generated real number, which is in the range [0,1).

Syntax

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

import randomrandom.random()
Copy after login

Note: random() cannot be accessed directly. You need to import the random module and then pass randomstaticObjectCall this method.

Return value

Returns a randomly generated real number, which is in the range of [0,1).

Example

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

#!/usr/bin/pythonimport random # 生成第一个随机数print "random() : ", random.random()# 生成第二个随机数print "random() : ", random.random()
Copy after login

The output result after running the above example is:

random() : 0.281954791393 random() : 0.309090465205
Copy after login

[Related recommendations]

1.Detailed explanation of mathematics and random numbers in the Python standard library (math package, random package)

2.Share the random module generation in Python Example tutorial of random numbers

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

4.Share Python random Example of a method to generate N non-repeating random numbers within a certain interval

5.Common methods and usage examples of Python random module (obtaining random numbers)

6.Common methods of Python random module

7.Python module learning: random random number generation

The above is the detailed content of Example tutorial of Python random() function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!