## Python random  : uniform()

This article demonstrates how to use `random.uniform()` function .The `random.uniform()` function returns a random floating-point number between a given range in Python.

Syntax :
random.uniform(start, stop)

## Parameter Values

ParameterDescription
startRequired. A number specifying the lowest possible outcome(included).
stopRequired. A number specifying the highest possible outcome(included).

#### Return Value :

` Returns the generated floating point random number between lower limit and upper limit.`

Note :
• The `random.uniform` function accepts two arguments and both the arguments are compulsory and both included in range.
• If you miss any of them, you will get a `TypeError: uniform() missing 1 required positional argument`.

Let see how to use the `random.uniform()` function to get a random float number within a range.

Sample Program :

`#importing random moduleimport randomx = random.uniform(100, 249.5)print("Random float number between range 100 to 249.5 is ", x)x = random.uniform(249.5, 100)print("Random float number between 10 and 100 is ", x)x = random.uniform(100.5, 1000.5)print("Random float number between 100.5 and 1000.5 is ", x )x = random.uniform(1000.5, 100.5)print("Random float number between 1000.5 and 100.5 is ", `

Output:

Random float number between range 100 to 249.5 is  208.937439961597

Random float number between 10 and 100 is  143.92858470055455

Random float number between 100.5 and 1000.5 is  274.4557908322393

Random float number between 1000.5 and 100.5 is  439.269021794589

### Points to remember about random.uniform()

The start value need not be smaller than the stop value.

• If `start <= stop` the `random.uniform()` function generates a random float number which is greater than or equal to the start number and less than or equal to the stop number.
• If  `stop <= start` the `random.uniform()` function generates a random float number which is greater than or equal to the stop number and less than or equal to the start number.
• For example, you can generate a random float number between 10 to 100 and also from 100 to 10. Both treated the same.

The step argument is not available in `random.uniform()`

********END OF ARTICLE*******

#### More Articles of Vishal Lodhi:

Name Views Likes
Python string zfill 114 0
Python string swapcase 92 0
Python string title 96 0
Python string startswith 102 0
Python string replace 144 0
Python string translate 84 0
Python string rpartition 85 0
Python string partition 74 0
Python string splitlines 113 0
Python string rsplit 79 0
Python string split 75 0
Python string rindex 81 0
Python string rfind 106 0
Python string upper 80 0
Python string lower 81 0
Python string maketrans 90 0
Python string strip 81 0
Python string rstrip 91 0
Python string lstrip 79 0
Python string rjust 96 0
Python string ljust 95 0
Python string len 81 0
Python string join 75 0
Python string casefold 82 0
Python string isprintable 84 0
Python string encode 78 0
Python string isdecimal 84 0
Python string isidentifier 78 0
Python string isupper 77 0
Python string istitle 79 0
Python string isspace 100 0
Python string isnumeric 101 0
Python string isdigit 82 0
Python string islower 84 0
Python string isalpha 95 0
Python string isalnum 101 0
Python string index 87 0
Python string find 93 0
Python string expandtabs() 81 0
Python string endswith 91 0
Python string count 86 0
Python string capitalize 77 0
Python string center 84 0
Python string Introduction 98 0
Python string Template 139 0
Python string Formatter 144 0
Python string printable 199 0
Python string whitespace 146 0
Python string punctuation 103 0
Python string octdigits 86 0
Python string hexdigits 103 0
Python string digits 79 0
Python string ascii_letters 344 0
Python string ascii_lowercase 146 0
Python string ascii_uppercase 156 0
Python random weibullvariate 164 0
python random paretovariate 133 0
Python random vonmisesvariate 178 0
Python random normalvariate 195 0
Python random lognormvariate 119 0
Python random gauss 120 0
Python random gammavariate 131 0
Python random expovariate 194 0
Python random betavariate 184 0
Python random triangular 116 0
Python random uniform 141 0
Python random random 116 0
Python random sample 182 0
Python random shuffle 178 0
Python random choices 234 0
Python random choice 165 0
Python random randint 148 0
Python random randrange 214 0
Python random getrandbits 140 0
Python random setstate 136 0
Python random getstate 178 0
Python random seed 168 1
Python random Introduction 175 0