Flowgorithm Random Function
Flowgorithm Random Function
In this tutorial, we will learn the Flowgorithm Random function. We can use the function to generate a random number in flowcharts. Random() is an intrinsic function. The Flowgorithm software predefines the function behavior.
The Flowgorithm random function returns an integer randomly between 0 and (n – 1). It is an in-built function that requires one input argument.
Function Syntax
The general syntax of the function is as follows:
Random(n)
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.
Random Function Examples
In this example, we will understand how to use the function in the flowcharts.
Randomly generate 0, 1
For Example, Random(2) generates either 0 or 1 output randomly. We can use this function to simulate a random sample space of 2.
For example, tossing a coin can be Heads(H) or Tails(T).
P(H) = 1/2 and similarly P(T) = 1/2
The flowchart below invokes the Random(2) function ten times and displays the output to the console window.
Notice that the output is random when the function is invoked several times.
A random number between 0 – 9
Random(10) This function generates a random number between 0 – 9.
In the example below, the flowchart invokes the Random() function ten times and displays the function output in 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 generate numbers from 1 to 10, both inclusive randomly. 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. The 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
Video
The probability of each outcome is 1/6. For example, the probability of six-sided dice rolling 4 is:
P(4) = 1/6 = 0.16666
When we roll the die n times where n is large, the probability of the die rolling
4 i.e P(4) limits to the value 1/6.
Let’s simulate the random experiment and calculate the probability. Assume we roll the die n = 10000 times, then the probability of the die rolling 4
P(4) = Number of Times the die rolls 4 / Total number of Random Experiments
The flowchart to calculate the probability of die rolling 4 by simulation 10000 random experiments is shown below:
Notice how we have used the Random() function. We check if the outcome of the die roll is 4.
The result of the flowchart:
This function can be used to simulate random experiments in Flowgorithm flowcharts.
Flowgorithm Tutorials
Flowgorithm flowchart tutorials on this website:
Flowgorithm official website:
For more information on Flowgorithm, visit the official website: