Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

euphoria
communitycreator

What is the rnd() method in Euphoria?

NDUKWE CHIDERA K.

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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 output
atom output

--use a for loop to print different floating numbers
for i = 1 to 6 do
    puts(1,"\n")
    output = rnd()
    print(1,output)
end for

Explanation

  • Line 1: We include the rand.e module from the built-in library.
  • Line 4: We declare the output variable.
  • Lines 7 and 11: We start and end a for loop.
  • Lines 9 and 10: We use the rnd() method and print the outcome to the screen.

RELATED TAGS

euphoria
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring