Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1.  
  2. import random
  3.  
  4. weeks = 10000 # hardware running time
  5. days_in_week = 7
  6. non_failure_periods = []
  7.  
  8. #variables to keep track of current hardware state
  9. can_fail = False
  10. error_free_count = 0
  11. days_since_last_failure = 0
  12.  
  13. for i in range(0, weeks):
  14. for i in range(0, days_in_week):
  15. if not can_fail:
  16. error_free_count += 1
  17. days_since_last_failure += 1
  18. if error_free_count > days_in_week: # if error free days have passed, hardware can fail
  19. error_free_count = 0
  20. can_fail = True
  21. if can_fail:
  22. rand = random.randint(0,6) # Assume 1/7 prob. of failure per day
  23. if rand == 0: # hardware failure
  24. non_failure_periods.append(days_since_last_failure)
  25. days_since_last_failure = 0
  26. can_fail = False # reboot
  27. else: # if it didn't fail today, just continue and count
  28. days_since_last_failure += 1
  29.  
  30. average = 0
  31. for a in non_failure_periods:
  32. average += float(a) / float(len(non_failure_periods))
  33.  
  34. print "Average non-failure period:", average
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement