Método aleatorio triangular () de Python
Ejemplo
Devuelve un número aleatorio entre 20 y 60 inclusive, pero probablemente más cercano a 20:
import random
print(random.triangular(20, 60, 30))
Definición y uso
El triangular()
método devuelve un número flotante aleatorio entre los dos números especificados (ambos incluidos), pero también puede especificar un tercer parámetro, el mode
parámetro.
El mode
parámetro le brinda la oportunidad de sopesar el posible resultado más cerca de uno de los otros dos valores de parámetro.
El mode
parámetro predeterminado es el punto medio entre los otros dos valores de parámetros, lo que no pesará el posible resultado en ninguna dirección.
Sintaxis
random.triangular(low, high, mode)
Valores paramétricos
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 |