vendredi 19 novembre 2021

Time-complexity of cummulative sum of random numbers ( from uniform distribution ) as long as sum is less than 1

What is the time-complexity of the following loop?

import random  
def cummulative_sum():
   a = 0
   while a < 1:
       a += random.random()
   return a

What promises me that the loop will stop? after all, random.random() could keep generating 0 all the time ( ofcourse, highly unprobable but still... ). How many times will it run? ( the answer depends on random.random() being a uniform probability, but I can't seem to link the mathematics to the complexity ).




Aucun commentaire:

Enregistrer un commentaire