Detailed explanation of Python basics uniform()

Y2J
Release: 2017-05-17 13:15:46
Original
4473 people have browsed it

Description

## The uniform() method will randomly generate the next real number, which is in the range [x, y].

Grammar

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

import random
random.uniform(x, y)
Copy after login

Note: uniform() cannot be accessed directly Yes, you need to import the random module, and then call this method through random

staticobject.

Parameters

x -- The minimum value of the random number.

y -- The maximum value of the random number.

Return value

Returns a floating point number.

Example

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

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import random
print "uniform(5, 10) 的随机数为 : ",  random.uniform(5, 10)
print "uniform(7, 14) 的随机数为 : ",  random.uniform(7, 14)
Copy after login

The output result after running the above example is:

uniform(5, 10) 的随机数为 :  6.98774810047
uniform(7, 14) 的随机数为 :  12.2243345905
Copy after login

[Related recommendations]

1.

Special recommendation: "php Programmer Toolbox" V0.1 version download

2.

Free Python video tutorial

3.

Detailed explanation of uniform() based on Python

The above is the detailed content of Detailed explanation of Python basics uniform(). 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