Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- def getErrStream(streamSize):
- """Creates error stream according to init parametrs"""
- errstream = []
- for i in range(0, streamSize):
- errstream.append(random.randrange(2))
- return errstream
- def analizeErrStream(errstream, k):
- """Calculates some characteristics of the error stream.
- Returns dictionary with them."""
- inPacket = False
- errcount = zerocount = pcount = sumplen = sumerrprob = 0
- i = 0
- while i < len(errstream):
- if errstream[i]:
- inPacket = True
- pcount += 1
- plen = 0
- perr = 0
- while i < len(errstream):
- #sumpacklen += 1
- if errstream[i]:
- errcount += 1
- perr += 1
- zerocount = 0
- else:
- zerocount += 1
- if zerocount > k:
- inPacket = False
- plen -= (zerocount - 1)
- zerocount = 0
- sumplen += plen
- sumerrprob += perr / plen
- break
- plen += 1
- i += 1
- i += 1
- print('Текущая длина:', plen)
- if inPacket:
- sumplen += plen
- sumerrprob += perr / plen
- print('Суммарная длина пакетов:', sumplen)
- return {'errprob': errcount / len(errstream), 'pkgcount': pcount,
- 'pkgavlen': sumplen / pcount, 'pkgavprob': sumerrprob / pcount}
- errstream = getErrStream(int(input('Введите длину потока ошибок: ')))
- print('Поток ошибок:', errstream)
- streaminfo = analizeErrStream(errstream, int(input('Введите допустимый интервал нулей в пакете: ')))
- print('Вероятность ошибки:', streaminfo['errprob'])
- print('Количество пакетов:', streaminfo['pkgcount'])
- print('Средняя длина пакета:', streaminfo['pkgavlen'])
- print('Средняя вероятность ошибки в пакете:', streaminfo['pkgavprob'])
Add Comment
Please, Sign In to add comment