What are the different ways to generate random numbers?
Answer Posted / chaitanya
Random module is the standard module that is used to generate the random number.
The method is defined as:
import random
random.random()
The statement random.random() method return the floating point number that is in the range of [0, 1). The function generates the random float numbers. The methods that are used with the random class are the bound methods of the hidden instances. The instances of the Random can be done to show the multi-threading programs that creates different instance of individual threads. The other random generators that are used in this are:
• randrange(a, b): it chooses an integer and define the range in-between [a, b). It returns the elements by selecting it randomly from the range that is specified. It doesn’t build a range object.
• uniform(a, b): it chooses a floating point number that is defined in the range of [a,b).Iyt returns the floating point number
• normalvariate(mean, sdev): it is used for the normal distribution where the mu is a mean and the sdev is a sigma that is used for standard deviation.
• The Random class that is used and instantiated creates an independent multiple random number generators.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
How is python an interpreted language?
What are the built-in types of python?
How do you convert a string to in python?
Why is python faster than r?
How do you convert string as a variable name in python?
How many basic types of functions are available in python?
How do I run a subprocess with pipes connected to both input and output?
Explain the uses of the modules sqlite3, ctypes, pickle, traceback, and itertools.
How can I learn python?
What is python best for?
What is a static method python?
Explain python’s pass by references vs pass by value. (Or) explain about python’s parameter passing mechanism?
What is self in python constructor?
Does Python support strongly for regular expressions?
Explain me what is pass in python?