Flowgorithm Random Function
Overview
In this tutorial, we will learn Flowgorithm Random function. We can use the function to generate a random number in flowcharts. Random() is an intrinsic function. The function behavior is predefined by the Flowgorithm software.
Function Syntax
The general syntax of the function is as follows:
Random(n)
The function requires one input argument. Random function returns an integer randomly between 0 and n – 1.
The argument is the upper limit of the random number that might be generated with the function. The number of arguments must match the function parameters. Otherwise, we will get an error during the flowchart runtime.
Examples
Randomly generate 0, 1
In this section we will understand some examples that use the function.
For Example, Random(2) generates output of either 0 or 1 randomly. Below flowchart invokes the Random(2) function ten times and displays the function output to the console window. Notice that the output is random.
Random(10) This function generates a random number between 0 – 9.
Below example flowchart invokes the Random() function ten times and displays the function output to the console window. Notice that the output is random.
Notice that the output of the function is not constant. The Random(10) function randomly generates a number within the interval [0,9].
Random numbers from 1 to 10
Sometimes, we do not want the zero number to be generated. For example, we may want to randomly generate numbers from 1 to 10 both inclusive. We can use the following expression:
Random(10) + 1
Dice Roll Example
There are six possible outcomes when we roll a fair six-sided die. The outcomes are 1,2,3,4,5,6. Dice roll randomly generates a number from 1 to 6. So, to simulate the dice roll we can use the following Flowgorithm expression:
Random(6) + 1
The probability of each outcome is 1/6.
—
Flowgorithm Tutorials
Flowgorithm flowchart tutorials on this website:
https://www.testingdocs.com/flowgorithm-flowchart-tutorial/
Flowgorithm Website
For more information on the Flowgorithm tool, please visit the official website at: