random.uniform( ) 函數(shù)教程與實例解析
1. uniform( ) 函數(shù)說明
random.uniform(x, y)方法將隨機生成一個實數(shù),它在 [x,y] 范圍內(nèi)。
2. uniform( ) 的語法與參數(shù)
2.1 語法
# _*_ coding: utf-8 _*_import randomrandom.uniform(x, y)
或
# _*_ coding: utf-8 _*_from random import uniformuniform(x, y)
提示:uniform 包含在random庫中,需要使用時需導(dǎo)入random庫。
2.2 參數(shù)
x -- 隨機數(shù)的最小值,包含該值。 y -- 隨機數(shù)的最大值,不包含該值。 返回一個浮點數(shù)3. 實例
例程:
# _*_ coding: utf-8 _*_import randomprint("uniform(1 , 6) 的隨機返回值為 : ", random.uniform(1 , 6))print("uniform(10, 16) 的隨機返回值為 : ", random.uniform(10, 16))運行結(jié)果:
#uniform(1 , 6) 的隨機返回值為 : 3.001161523486847
#uniform(10, 16) 的隨機返回值為 : 13.70906147017741
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對武林站長站的支持。如果你想了解更多相關(guān)內(nèi)容請查看下面相關(guān)鏈接
新聞熱點
疑難解答