Random Uniform PythonIn this tutorial, we will discuss the uniform() method present in the random module of Python and also how it can be used by importing NumPy. The uniform() returns a floating-point number or a range of numbers between the specified limits. The syntax for using uniform() is- Here, "a" represents the upper bound & b represents the lower bound. Let us have a look at some examples that demonstrates its usage in Python programs. The following program illustrates how it can be used in a python program- Output: The random number between 8 and 12 is: 10.14646142251812 Explanation- Let's understand what happened in the above program-
Let us have a glance at one more program where we have followed the same approach but provided the float values as upper and lower bounds. Output: The random number between 9.7 and 14.3 is : 11.521121715281813 Explanation- The procedure is the same as the previous program but here we can observe it displays the required output even when we provide decimal values. We all know that the NumPy module is used in Python to carry out different mathematical operations and because of the kind of in-built functions this module provides, our code becomes less complex and more efficient. Let us see how we can use uniform() here, Consider the program given below, Output: The resultant array is: [0.09310829 0.97165592 0.48385998 0.2425227 ] Explanation- It's time to know the explanation of the above program-
Now, let's check out another program- Output: The resultant array is: [[0.5488135 0.71518937 0.60276338] [0.54488318 0.4236548 0.64589411] [0.43758721 0.891773 0.96366276]] <class 'numpy.ndarray'> Explanation- Let's understand what happened here,
Finally, it's time to discuss the last program of this article, Output: The resultant array is: [53.52508358 57.01897669 54.6580309 53.44254684 50.89675079] <class 'numpy.ndarray'> Explanation-
ConclusionIn this tutorial, we learned what is uniform() and how it can be used in various python programs. Next TopicRelational Operators in Python |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India