I use RevitPythonShell and after unsuccessfully finding an error in my code, I found that the problem is due to the random module acting weirdly. Almost all the functions in the random module seem to leave half the capabilities untouched.
random.sample is just a selection of the first half of the list. random.uniform - Generates numbers smaller than the average of two boundaries. random.random () only generates numbers from 0 to 0.5.
The code below is a revitpythonshell terminal. Can someone help me understand what is happening?
>>> import random
>>>
>>> for _ in range(1000):
... if random.random() >= 0.5: print("hello !!")
...
>>>
>>> max = 0
>>> for _ in range(1000):
... rand = random.random()
... if rand > max: max = rand
...
>>> max
0.499520565070528
>>>
>>>
>>> nums = list(range(10))
>>> for _ in range(1000):
... if random.sample(nums, 1)[0] >= 5: print("hello")
...
>>>
>>>
>>> a = 3.5
>>> b = 4.75
>>> half = (a+b)/2
>>> for _ in range(1000):
... if random.uniform(a,b) > half: print("Hello !!!")
...
>>>
>>>
>>>
source
share