Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Numpy exercise
  • pandas
  • Matplotlib
  • Data visulisation
  • EDA
  • Machin Learning
  • Deep Learning
  • NLP
  • Data science
  • ML Tutorial
  • Computer Vision
  • ML project
Open In App
Next Article:
Chi-Square Distribution in NumPy
Next article icon

Uniform Distribution in NumPy

Last Updated : 22 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A Uniform Distribution is used when all the numbers in a range have the same chance of being picked. For example, if we choose a number between 10 and 20 and every number in that range is just as likely as any other. In Python’s NumPy library you can generate random numbers following a Uniform Distribution using the numpy.random.uniform() method. The syntax is:

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

  • low : The lower bound of the range (inclusive). Default is 0.0.
  • high : The upper bound of the range (exclusive). Default is 1.0.
  • size : The shape of the returned array.

Example 1: Generate a Single Random Number

In this example we can see how to generate a single random number from a default Uniform Distribution (low=0, high=1):

Python
import numpy as np  random_number = np.random.uniform() print(random_number) 

Output:

0.1466964230422637

To generate multiple random numbers:

Python
random_numbers = np.random.uniform(size=5) print(random_numbers) 

Output:

[0.72798597 0.35286575 0.10228773 0.56598948 0.03552713]

Visualizing the Uniform Distribution

Visualizing the generated numbers helps in understanding their behavior. Let’s see a example to plot a histogram of random numbers using numpy.random.uniform function.

Python
import numpy as np import matplotlib.pyplot as plt import seaborn as sns  low = 10   high = 20   size = 1000    data = np.random.uniform(low=low, high=high, size=size) sns.histplot(data, bins=30, kde=False, color='skyblue', edgecolor='black')  plt.title(f"Uniform Distribution (Range: {low} to {high})") plt.xlabel("Value") plt.ylabel("Frequency") plt.grid(True) plt.show() 

Output:

Uniform-Distribution

Uniform Distribution

The image above shows a Uniform Distribution between 10 and 20. This means every number in that range is equally likely to happen. The bars in the histogram show that the values from 10 to 20 appear about the same number of times.




Next Article
Chi-Square Distribution in NumPy

J

Jitender_1998
Improve
Article Tags :
  • Python
  • Python numpy-Random
  • Python-numpy
Practice Tags :
  • python

Similar Reads

  • Chi-Square Distribution in NumPy
    The Chi-Square Distribution is used in statistics when we add up the squares of independent random numbers that follow a standard normal distribution. It is used in hypothesis testing to check whether observed data fits a particular distribution or not. In Python you can use the numpy.random.chisqua
    2 min read
  • Python - Uniform Distribution in Statistics
    scipy.stats.uniform() is a Uniform continuous random variable. It is inherited from the of generic methods as an instance of the rv_continuous class. It completes the methods with details specific for this particular distribution. Parameters : q : lower and upper tail probability x : quantiles loc :
    2 min read
  • Normal Distribution in NumPy
    The Normal Distribution also known as the Gaussian Distribution is one of the most important distributions in statistics and data science. It is widely used to model real-world phenomena such as IQ scores, heart rates, test results and many other naturally occurring events. numpy.random.normal() Met
    2 min read
  • Binomial Distribution in NumPy
    The Binomial Distribution is a fundamental concept in probability and statistics. It models the number of successes in a fixed number of independent trials where each trial has only two possible outcomes: success or failure. This distribution is widely used in scenarios like coin flips, quality cont
    2 min read
  • Exponential Distribution in NumPy
    The Exponential Distribution is a fundamental concept in probability and statistics. It describe the time between events in a Poisson process where events occur continuously and independently at a constant average rate. You can generate random numbers which follow exponential Distribution using nump
    2 min read
  • Python - Uniform Discrete Distribution in Statistics
    scipy.stats.randint() is a uniform discrete random variable. It is inherited from the of generic methods as an instance of the rv_discrete class. It completes the methods with details specific for this particular distribution. Parameters : x : quantiles loc : [optional]location parameter. Default =
    2 min read
  • 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
    1 min read
  • NumPy Introduction
    NumPy(Numerical Python) is a fundamental library for Python numerical computing. It provides efficient multi-dimensional array objects and various mathematical functions for handling large datasets making it a critical tool for professionals in fields that require heavy computation. Table of Content
    7 min read
  • Normal Distribution Plot using Numpy and Matplotlib
    In this article, we will see how we can create a normal distribution plot in python with numpy and matplotlib module.  What is Normal Distribution?Normal Distribution is a probability function used in statistics that tells about how the data values are distributed. It is the most important probabili
    3 min read
  • sympy.stats.Uniform() in Python
    With the help of sympy.stats.Uniform() method, we can get the continuous random variable which represents the Uniform distribution. Syntax : sympy.stats.Uniform(name, left, right) Where, left and right are real number, -oo < left, left < right < +oo Return : Return the continuous random var
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences