How would I generate random numbers to 2 decimal places in the range (0, 0.1]. My code so far is generating numbers with two decimal places in the range [0, 0.1]:
radius = round(random.uniform(0, 0.1), 2)
Perhaps the easiest way to solve your problem is to think in terms of integers, not floating-point numbers.
You basically want possible random numbers like 0.01, 0.02, 0.03, ..., 0.09, 0.10.
First you generate an integer between 1 to 10 inclusive, then you divide by 100.0 to get a floating-point number.
Here is the code:
x = random.randint(1, 10)
y = x / 100.0
Documentation: random.randint(a, b)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With