What is the rnd() method in Euphoria?
Overview
The rnd() method is an inbuilt method in Euphoria that generates a random number between 0 and 1. This method randomly generates floating-point numbers between 0.0 and 1.0 (both inclusive).
This is unlike the rand() method, which only returns integer numbers.
Syntax
rnd()
Parameter
This method has no parameters.
Return value
This method returns a random value between 0.0 and 1.0, with both ends inclusive.
Code
The code below shows how the rnd() method generates a random floating-point number.
include std/rand.e--declare the variable to hold the outputatom output--use a for loop to print different floating numbersfor i = 1 to 6 doputs(1,"\n")output = rnd()print(1,output)end for
Explanation
- Line 1: We include the
rand.emodule from the built-in library. - Line 4: We declare the output variable.
- Lines 7 and 11: We start and end a
forloop. - Lines 9 and 10: We use the
rnd()method and print the outcome to the screen.