Python Forum
random.uniform is not working correctly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
random.uniform is not working correctly
#6
(Feb-06-2020, 02:31 PM)Gribouillis Wrote: With simpler notations, you are doing
def func(a, b, c, d):
    x = uniform(a, b)
    y = uniform(c, d)
    z = uniform(x, y)
    return z
With this definition, func() can return any value between min(a, b, c, d) and max(a, b, c, d). In particular you cannot expect a special relation between z and the values in the middle of the 4 arguments.


a = 32.36825432569349
b = 32.367919037002075
c = 32.36844462412729
d = 32.367774046912494


def func(a, b, c, d):
    x = random.uniform(a, b)
    y = random.uniform(c, d)
    z = random.uniform(x, y)
    return z


print(func(a=a, b=b, c=c, d=d))
print(a > func(a=a, b=b, c=c, d=d))
print(b > func(a=a, b=b, c=c, d=d))
print(c > func(a=a, b=b, c=c, d=d))
print(d > func(a=a, b=b, c=c, d=d))
Same problem
True
False
True
False
Reply


Messages In This Thread
RE: random.uniform is not working correctly - by dron4ik86 - Feb-06-2020, 02:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  If statement not working correctly? MrKnd94 2 866 Nov-16-2022, 02:49 AM
Last Post: deanhystad
  Finding MINIMUM number in a random list is not working Mona 5 3,119 Nov-18-2019, 07:27 PM
Last Post: ThomasL
  random selection of song and artist not working Unknown_Relic 2 2,394 Nov-08-2019, 02:06 PM
Last Post: perfringo
  Working with Random Generated Numbers YoungGrassHopper 4 3,302 Sep-10-2019, 06:53 AM
Last Post: YoungGrassHopper
  How do you know when a library is working correctly? grjmmr 1 2,465 Jul-24-2018, 03:08 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020