Thursday, November 20, 2025
HomeLanguagesGenerate Random Numbers From The Uniform Distribution using NumPy

Generate Random Numbers From The Uniform Distribution using NumPy

Random numbers are the numbers that cannot be predicted logically and in Numpy we are provided with the module called random module that allows us to work with random numbers. To generate random numbers from the Uniform distribution we will use random.uniform() method of random module. 

Syntax:

numpy.random.uniform(low = 0.0, high = 1.0, size = None)  

In uniform distribution samples are uniformly distributed over the half-open interval [low, high) it includes low but excludes high interval.

Examples:

Python3




# importing module
import numpy as np
  
  
# numpy.random.uniform() method
r = np.random.uniform(size=4)
  
# printing numbers
print(r)


Output:

[0.3829765  0.50958636 0.42844207 0.4260992  0.3513896 ]

Example 2:

Python3




# importing module
import numpy as np
  
  
# numpy.random.uniform() method
random_array = np.random.uniform(0.0, 1.0, 5)
  
# printing 1D array with random numbers
print("1D Array with random values : \n", random_array)


Output:

1D Array with random values :
[0.2167103  0.07881761 0.89666672 0.31143605 0.31481039]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32404 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6776 POSTS0 COMMENTS
Nicole Veronica
11924 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11994 POSTS0 COMMENTS
Shaida Kate Naidoo
6904 POSTS0 COMMENTS
Ted Musemwa
7160 POSTS0 COMMENTS
Thapelo Manthata
6859 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS