[英]Can python output multiple random numbers? How can they be uniformly distributed and also be random?
我已經開始學習python。 我正在使用《用於計算科學的Python腳本》一書。 我正在嘗試編寫一個程序
"Write a script that prints a uniformly distributed random number between
−1 and 1. The number should be written with four decimals as implied by
the %.4f format."
我正在使用random.uniform獲取隨機數。 但是我找不到一個能獲得多個隨機數的函數。 例如我的代碼是
print random.uniform(-1, 1)
它給出輸出0.238638833859。 但是我想要多個統一的隨機數。 誰能告訴我一個功能? 還有一件事,我想學習python以編寫腳本。 那么有人能推薦一本好書嗎? 我想將python用於網絡自動化。 我正在使用的書對此並不理想。 請給我推薦一本好書。
您是否正在尋找這樣的東西:
[random.uniform(-1+x, 1+x) for x in range(10)]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.