Pythonランダムtriangle()メソッド
例
20から60までの、そして含まれているが、おそらく20に近い乱数を返します。
import random
print(random.triangular(20, 60, 30))
定義と使用法
このtriangular()
メソッドは、指定された2つの数値(両方を含む)の間にランダムな浮動小数点数を返しますが、3番目のパラメーターであるmode
パラメーターを指定することもできます。
このmode
パラメーターは、他の2つのパラメーター値のいずれかに近い結果を比較検討する機会を提供します。
パラメータのmode
デフォルトは、他の2つのパラメータ値の中間点であり、どの方向でも起こりうる結果を評価しません。
構文
random.triangular(low, high, mode)
パラメータ値
Parameter | Description |
---|---|
low | Optional. A number specifying the lowest possible outcome. Default 0 |
high | Optional. A number specifying the highest possible outcome. Default 1 |
mode | Optional. A number used to weigh the result in any direction. Default the midpoint between the low and high values |