Last active
December 29, 2019 00:59
-
-
Save dsh0005/11d8f4b631561bc5286cd50fe00e6c89 to your computer and use it in GitHub Desktop.
Python bitting generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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