❮ Random Methods ExampleReturn a random number between, and included, 20 and 60, but most likely closer to 20: import random print(random.triangular(20, 60, 30)) Try it Yourself » Definition and UsageThe
The The Syntax
random.triangular(low, high, mode) Parameter Values
❮ Random Methods View Discussion Improve Article Save Article View Discussion Improve Article Save Article
Example 1:
Output : 22.614510550239572 Example 2: If we generate the number multiple times we can probably identify the bias.
Output : 58.645768016894735 46.690692250503226 33.57590419190895 52.331804090351305 33.09451214875767 12.03845752596168 32.816080679206294 20.4739124559502 82.49208123077557 63.511062284733015 Example 3: We can visualize the triangular pattern by plotting a graph.
Output : View Discussion Improve Article Save Article View Discussion Improve Article Save Article With the help of numpy.random.triangular() method, we can get the random samples from triangular distribution from interval [left, right] and return the random samples by using this method.
Example #1 : In this example we can see that by using numpy.random.triangular() method, we are able to get the random samples of triangular distribution and return the numpy array. Python3
Output : Example #2 : Python3
Output : |