uniform() method in Python Random module Last Updated : 11 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The uniform() method in Python generates a random floating-point number within a specified range. It belongs to the random module and is commonly used when a continuous random number is needed. For example, suppose we need to generate a random float number between 1 to 10 Python import random print(random.uniform(1,10)) Output2.0014240090730393 Explanation: random.uniform(1,10) generates a random float number between 1 to 10 (inclusive).Syntax of uniform() methodrandom.uniform(l, u)Parametersl - lower bound (inclusive).u - upper bound (inclusive).Return Type: uniform(l, u) returns a float value.Examples of uniform() methodExample 1. Generate random numberGenerating random float number using uniform() method. Python import random # initializing bounds l = 6 u = 9 print(random.uniform(l, u)) Output6.706427492848576 Explanation: import the random module before using the uniform method.random.uniform(l, u) will generate a radom float number between 'l' and 'u'.Example 2. Generating Random Latitudes and Longitudes.uniform() method can be used to generate random latitude and longitude coordinates, including negative floating-point values. Python import random lat = random.uniform(-90, 90) lon = random.uniform(-180, 180) print("Random Location: ",lat,",", lon) OutputRandom Location: 73.3285434510266 , -82.611145839544 Explanation: random.uniform(-90, 90) returns a latitude between -90 and 90 (inclusive).random.uniform(-180, 180) returns a longitude between -180 and 180 (inclusive). Comment More infoAdvertise with us Next Article Python Random Module M manjeet_04 Follow Improve Article Tags : Misc Python Python-Library Python-Functions Python-Built-in-functions +1 More Practice Tags : Miscpythonpython-functions Similar Reads Python Random Module Python Random module generates random numbers in Python. These are pseudo-random numbers means they are not truly random. This module can be used to perform random actions such as generating random numbers, printing random a value for a list or string, etc. It is an in-built function in Python.Appli 6 min read Python - random.seed( ) method random.seed() method in Python is used to initialize the random number generator, ensuring the same random numbers on every run. By default, Python generates different numbers each time, but using .seed() allows result reproducibility.It's most commonly used in:Machine Learning- to ensure model cons 4 min read random.getstate() in Python random() module is used to generate random numbers in Python. Not actually random, rather this is used to generate pseudo-random numbers. That implies that these randomly generated numbers can be determined. random.getstate() The getstate() method of the random module returns an object with the curr 1 min read random.setstate() in Python Random module is used to generate random numbers in Python. Not actually random, rather this is used to generate pseudo-random numbers. That implies that these randomly generated numbers can be determined. random.setstate() The setstate() method of the random module is used in conjugation with the g 2 min read random.getrandbits() in Python random module is used to generate random numbers in Python. Not actually random, rather this is used to generate pseudo-random numbers. That implies that these randomly generated numbers can be determined. random.getrandbits() The getrandbits() method of the random module is used to return an intege 1 min read randrange() in Python The randrange() function in Python's random module is used to generate a random number within a specified range. It allows defining a start, stop, and an optional step value to control the selection of numbers. Unlike randint(), which includes the upper limit, randrange() excludes the stop value. Ex 4 min read randint() Function in Python randint() is an inbuilt function of the random module in Python3. The random module gives access to various useful functions one of them being able to generate random numbers, which is randint(). In this article, we will learn about randint in Python.Python randint() Method SyntaxSyntax: randint(sta 6 min read Python Numbers | choice() function choice() is an inbuilt function in Python programming language that returns a random item from a list, tuple, or string. Syntax: random.choice(sequence) Parameters: sequence is a mandatory parameter that can be a list, tuple, or string. Returns: The choice() returns a random item. Note:We have to im 1 min read Python - random.choices() method The choices() method returns multiple random elements from the list with replacement. Unlike random.choice(), which selects a single item, random.choices() allows us to select multiple items making it particularly useful for tasks like sampling from a population or generating random data.Example:Pyt 3 min read random.sample() function - Python sample() is an built-in function of random module in Python that returns a particular length list of items chosen from the sequence i.e. list, tuple, string or set. Used for random sampling without replacement. Example:Pythonfrom random import sample a = [1, 2, 3, 4, 5] print(sample(a,3))Output[2, 5 2 min read Like