Write a Python program to generate random float numbers in a specific numerical range


This program generates 10 random floating-point numbers between x and 100, where x starts at 0 and increases by 1 in each iteration of the loop. The random.uniform() method from the random module is used to generate random floating-point numbers within a given range. Here's how the program works:

  • The random module is imported to generate random numbers.
  • A for loop is used to iterate 10 times.
  • In each iteration, a random number is generated using the random.uniform() method with x as the lower bound and 100 as the upper bound. The round() function is used to round the number to 3 decimal places.
  • The resulting number is printed to the console.

Note that in the first iteration of the loop, x is 0, so the random number generated will be between 0 and 100. In the second iteration, x is 1, so the random number generated will be between 1 and 100, and so on until the 10th iteration where x is 9 and the random number generated will be between 9 and 100.

Source Code

import random
for x in range(10):
	res = round(random.uniform(x, 100),3)
	print(res)

Output

42.912
67.523
87.538
43.369
80.415
5.708
14.827
16.431
18.942
78.732

Example Programs