描述
這個uniform()方法返回一個隨機浮點數 r,使得 x 小於或等於 r 且 r 小於 y。
用法
以下是語法uniform()方法 -
uniform(x, y)
注意− 該函數不可直接訪問,因此需要導入uniform模塊,然後使用隨機靜態對象調用該函數。
參數
x− 設置隨機浮點數的下限。
y− 設置隨機浮點數的上限。
返回值
此方法返回一個浮點數 r,使得 x <= r < y。
示例
下麵的例子展示了 uniform() 方法的用法。
#!/usr/bin/python3
import random
print ("Random Float uniform(5, 10):", random.uniform(5, 10))
print ("Random Float uniform(7, 14):", random.uniform(7, 14))
輸出
讓我們運行上麵的程序。這將產生以下結果 -
Random Float uniform(5, 10): 5.52615217015 Random Float uniform(7, 14): 12.5326369199
相關用法
- Python 3 Number tan()用法及代碼示例
- Python 3 Number atan()用法及代碼示例
- Python 3 Number ceil()用法及代碼示例
- Python 3 Number cos()用法及代碼示例
- Python 3 Number max()用法及代碼示例
- Python 3 Number sin()用法及代碼示例
- Python 3 Number round()用法及代碼示例
- Python 3 Number acos()用法及代碼示例
- Python 3 Number shuffle()用法及代碼示例
- Python 3 Number fabs()用法及代碼示例
- Python 3 Number log()用法及代碼示例
- Python 3 Number randrange()用法及代碼示例
- Python 3 Number hypot()用法及代碼示例
- Python 3 Number exp()用法及代碼示例
- Python 3 Number degrees()用法及代碼示例
- Python 3 Number sqrt()用法及代碼示例
- Python 3 Number seed()用法及代碼示例
- Python 3 Number log10()用法及代碼示例
- Python 3 Number radians()用法及代碼示例
注:本文由純淨天空篩選整理自 Python 3 - Number uniform() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。