Quote:
Originally Posted by phillip1882
Code:
while z <100:
y = random.randint(0,100)
x = random.randint(0,y)
z = random.randint(0,x)
|
Quote:
Originally Posted by alexander
Actually that code will never halt, because while you may have a random number equal to 100, your algo will never return z that is larger then 100.
|
This code
will finish on average after

iterations of the loop, because random.randint(0,100) can return integers including 0 and 100, and “100 < 100” evaluates to false.
Alexander, perhaps you’re confusing python’s random.randint with the random function of other languages, where RANDOM(100) typically returns no integer greater than 99? Or confused “<” for “<=”?
----------------
Moderator: Computers and Technology; Medical Science; Science Projects and Homework; Philosophy of Science; Physics and Mathematics; Environmental Studies
