How to Generate List of Random Float Numbers in Python?
Hi Dev,
Now, let's see post of how to generate list of random float numbers in python. I would like to show you python create list from random float tutorial example. Here you will learn create list of numbers from random float in python tutorial example. This article goes in detailed on python create list random float. you will do the following things for create list of numbers python random float.
If you are looking to generate a list of random float numbers in python, there are several ways to create a list of random float numbers in python. here, I will give you two examples using random and numpy library for creating a new list of random float numbers in python. so, let's see the example code.
Example 1:
main.py
import random
import numpy as np
low = 0.2
high = 2.9
# Python Generate List of Random Float Numbers Example
floatList = [random.uniform(low, high) for _ in range(5)]
print(floatList)
Output:
[1.2810449626587266, 1.5206898226328796, 1.9837497458591744, 0.8076086725933713, 0.6949857530454222]
Example 2: Random Float with 2 Decimal Point
main.py
import random
import numpy as np
low = 0.2
high = 2.9
# Python Generate List of Random Float Numbers Example
floatList = [round(random.uniform(low, high), 2) for _ in range(5)]
print(floatList)
Output:
[0.96, 1.77, 1.3, 1.83, 1.87]
- Get Last 2 Digits of Number in Python Tutorial Example
- How to Sum of First and Last Digit of Number in Python?
- How to Get First and Last Digit of Number in Python?
- Get the Last Digit of Number in Python Tutorial Example
- Get the First Digit of Number in Python Tutorial Example
- How to Remove All Decimals from Number in Python?
- How to Convert String to Float with 2 Decimal Places in Python?
- How to Format Number to 2 Decimal Places in Python?