Skip to content

Instantly share code, notes, and snippets.

@dsh0005
Last active December 29, 2019 00:59
Show Gist options
  • Save dsh0005/11d8f4b631561bc5286cd50fe00e6c89 to your computer and use it in GitHub Desktop.
Save dsh0005/11d8f4b631561bc5286cd50fe00e6c89 to your computer and use it in GitHub Desktop.
Python bitting generator
#!/usr/bin/env python3
# encoding=utf-8
# vim: set nobomb:
from random import SystemRandom
from typing import List, Optional
def bitting(codes: int, macs: int, length: int, progress: Optional[List[int]]=None) -> List[int]:
if 0 == length:
return progress
elif progress:
return bitting(codes, macs, length - 1, progress + [SystemRandom().choice([cut for cut in range(codes) if abs(cut - progress[-1]) <= macs])])
else:
return bitting(codes, macs, length - 1, [SystemRandom().choice(range(codes))])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment