To find a random number between 0 and 1 we will make use of the random.rand() function from the NumPy module.
Code Example 1: random.rand(1)
# Step 1: Import numpy library
import numpy as np
# Step 2: Use random.rand function and get an array
random_no = np.random.rand(1)
# Step 3: Print the first element of the array
print("Random Number Between 0-1 is :", random_no[0])
Output:
0.5152378042391298
Code Example 2: random.random()
# Step 1: Import numpy library
import numpy as np
# Step 2: use random.random() to generate random number between 0 and 1
random_no = np.random.random()
# Step 3: print the output
print(f"Random number between 0-1 is {random_no}")
Output:
Random number between 0-1 is 0.49419449525748516

Have Questions? Post them here!
- Program 11: Calculate Percentage - 1000+ Python Programs
- Program 8: Multiply Two Numbers - 1000+ Python Programs
- Program 1: Print Hello World! - 1000+ Python Programs
- 20 - Python - Print Colors for Text in Terminal - 1000+ Python Programs
- Program 15: Find String is a Palindrome or Not - 1000+ Python Programs
- 17: Find Factorial of a Number - 1000+ Python Programs
- Program 13: Reverse a String - 1000+ Python Programs
- 18: Get Sub List By Slicing a Python List - 1000+ Python Programs
- Program 9: Divide Two Numbers - 1000+ Python Programs
- Program 7: Find Difference of Two Numbers - 1000+ Python Programs
- Program 14: Sum of Even Numbers from 1 to 100 - 1000+ Python Programs
- Program 10: Modulo of Two Numbers - 1000+ Python Programs
- 16: Find the largest element in a List - 1000+ Python Programs
- Python Program: Use NumPy to generate a random number between 0 and 1
- Program 2: Print your name using print() function - 1000+ Python Programs
- 19: Simple Calculator using built-in functions - 1000+ Python Programs
- Program 6: Find Sum of Two Floating Numbers - 1000+ Python Programs
- Program 12: Calculate Area and Circumference of Circle - 1000+ Python Programs
- Program 5: Find Sum of Two Integer Numbers - 1000+ Python Programs
- Program 4: Input Name and Age and Print - 1000+ Python Programs
- Program 3: Print the name of user as input - 1000+ Python Programs
- SharePoint CAML query error - The XML source is not correct - SharePoint
- Detect swipes on Android Activity - Android
- Android RatingBar Example - Android
- Disable Apps from Opening on Mac Startup (Login items) - MacOS
- Cant find System Preferences... under macOS Ventura Apple Menu? - MacOS
- How to upgrade Docker Desktop on Mac - MacOS
- How to migrate Kaizala to Microsoft Teams - Teams
- Generate Project Dependency tree using Gradle Command - Gradle