A random number is a number that is generated without any form of bias, usually from within a specified range.
Random number functions in programming languages are used to generate a number(s), which can make a predetermined decision based on the random number that is generated. In Euphoria, the rand()
method is an in-built function that allows us to generate random numbers.
The rand()
method generates random numbers whenever it is called. These random numbers cannot be greater than the maximum value that is passed as the function argument.
rand(max_value)
max_value
: The max_value
parameter is an atom
or a sequence
of integers that indicate the highest value of the random numbers that are generated.The generated random number is returned for use.
Note: To use this function, we have to include the
rand.e
file, which is part of Euphoria’s standard library, in our program code like so:
include std/rand.e
The code written below will generate random numbers for the atom
and the sequence
in the for
loop. Every time we click the “Run” button, a new set of random numbers will be generated.
include std/rand.eatom num1 = 5sequence numSet = {4,5,6}for i = 1 to 4 doprint(1,rand(num1))puts(1,'\n')print(1,rand(numSet))puts(1,'\n')end for
rand.e
file from the standard library in Euphoria.num1
and numSet
, which will serve as the max_value
parameter of the rand
function.for
loop, which will print the randomly generated numbers for three iterations, as is indicated in the loop condition.rand()
method is called with the max_value
that was declared earlier as the parameter.RELATED TAGS
CONTRIBUTOR