Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- weeks = 10000 # hardware running time
- days_in_week = 7
- non_failure_periods = []
- #variables to keep track of current hardware state
- can_fail = False
- error_free_count = 0
- days_since_last_failure = 0
- for i in range(0, weeks):
- for i in range(0, days_in_week):
- if not can_fail:
- error_free_count += 1
- days_since_last_failure += 1
- if error_free_count > days_in_week: # if error free days have passed, hardware can fail
- error_free_count = 0
- can_fail = True
- if can_fail:
- rand = random.randint(0,6) # Assume 1/7 prob. of failure per day
- if rand == 0: # hardware failure
- non_failure_periods.append(days_since_last_failure)
- days_since_last_failure = 0
- can_fail = False # reboot
- else: # if it didn't fail today, just continue and count
- days_since_last_failure += 1
- average = 0
- for a in non_failure_periods:
- average += float(a) / float(len(non_failure_periods))
- print "Average non-failure period:", average
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement