How to use python's random

(*-*)浩
Release: 2019-06-24 16:35:51
Original
3963 people have browsed it

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

How to use python's random

Grammar (Recommended learning: Python video tutorial)

The following is random() Method syntax:

import random

random.random()
Copy after login

Note: random() cannot be accessed directly. 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, which is in the range of [0,1).

Example

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

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
import 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

For more Python-related technical articles, please visit the Python Tutorial column to learn!

The above is the detailed content of How to use python's random. 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template