Home  >  Article  >  Backend Development  >  Detailed explanation of Python basics uniform()

Detailed explanation of Python basics uniform()

Y2J
Y2JOriginal
2017-05-17 13:15:464463browse

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)

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)

The output result after running the above example is:

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

[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!

Statement:
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