Python random.triangular()
Python random.triangular()
triangular() is a built-in method in the random module. It returns a random floating-point number within a range, biased toward one extreme.
Syntax: Random.triangular(low, high, mode).
Parameters:
low: The lower bound of the random number
high: The upper bound of the random number
mode: An additional bias; low < mode < high . If the parameters are (10, 100, 20), then due to the bias, most of the random numbers generated will be closer to 10 than to 100.
Returns: A random floating number
Example 1:
# import the random module
import random
# determining the values of the parameters
low = 10
high = 100
mode = 20
# using the triangular() method
print(random.triangular(low, high, mode))
Output:
22.614510550239572
Example 2: If we generate this number multiple times, we can roughly determine its deviation.
# import the random module
import random
#determining the values of the parameters
low=10
high = 100
mode=20
# running the triangular method with the
# same parameters multiple times
for i in range(10):
Print(random.triangular(low, high, mode))
Output: