{"id":25515,"date":"2021-11-19T09:12:46","date_gmt":"2021-11-19T03:42:46","guid":{"rendered":"https:\/\/python-programs.com\/?p=25515"},"modified":"2021-11-19T09:12:46","modified_gmt":"2021-11-19T03:42:46","slug":"python-random-triangular-method-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-random-triangular-method-with-examples\/","title":{"rendered":"Python Random triangular() Method with Examples"},"content":{"rendered":"

Random triangular() Method in Python:<\/strong><\/p>\n

The triangular() method returns a random floating number between the two specified numbers (both included), but a third parameter, the mode parameter, can also be specified.<\/p>\n

The mode parameter allows you to weigh the possible outcomes in relation to one of the other two parameter values.<\/p>\n

The mode parameter is set to the midpoint between the other two parameter values, and it does not weigh the possible outcomes in any direction.<\/p>\n

Syntax:<\/strong><\/p>\n

random.triangular(low, high, mode)<\/pre>\n

Parameters<\/strong><\/p>\n

low:<\/strong> This is Optional. A number indicating the lowest possible outcome.
\n0 is the default.<\/p>\n

high:<\/strong> This is Optional. A number indicating the highest possible outcome.
\n1 is the default.<\/p>\n

mode:<\/strong> This is Optional. A number that is used to weigh the outcome in any direction.
\nSet the default value to the midpoint between the low and high values.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given first number = 10\r\nGiven second number = 40\r\nGiven mode = 15<\/pre>\n

Output:<\/strong><\/p>\n

The random floating-point number between 10 and 40 = 16.45838431286139<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given first number = 5\r\nGiven second number = 15\r\nGiven mode = 8<\/pre>\n

Output:<\/strong><\/p>\n

Enter some random number = 5\r\nEnter some random number = 15\r\nEnter some random number = 8\r\nThe random floating-point number between 5 and 15 = 6.479018408138248<\/pre>\n

Random triangular() Method with Examples in Python<\/h2>\n