Computer Science, asked by AkarshGRao1519, 11 months ago

Give an example of ""random()""

Answers

Answered by sumitadutta445
0

It generates any ( float ) random number between 0 and 1 .

import random // importing random from random operations

print ("A random number between 0 and 1 is " ,end = "" )

Output:-

A random number between 0 and 1 is 0.510723453452104

Answered by letmeanswer12
1

Example of random() function

Explanation:

Functions in the random module depend on the random() function of a pseudo-random number generator, which produces a random float number between 0.0 to 1.0.  This number is used to generate a random float number less than 1 and greater or equal to 0.

  • Syntax - random.random()
  • Arguments - The function doesn't need any arguments.
  • Return Value - Generates a random float number between 0.0 to 1.0.  

Example:

  • # using random() to generate a random number  
  • # between 0 and 1  
  • print ("A random number between 0 and 1 is : ", end="")  
  • print (random.random())  
  • A random number between 0 and 1 is : 0.510721762520941

Similar questions