27 lines
883 B
Python
27 lines
883 B
Python
import itertools
|
|
from typing import Iterator, Set
|
|
|
|
class NameGenerator:
|
|
def __init__(self):
|
|
self._name_iterator = self._create_iterator()
|
|
self.used_names = set()
|
|
|
|
def _create_iterator(self) -> Iterator[str]:
|
|
"""
|
|
Generates obfuscated names like: vIl1lO0o0Z2z2...
|
|
"""
|
|
patterns = ['Il1l', 'O0o0', 'Z2z2', 'S5s5', 'B8b8', 'Q9q9']
|
|
for length in itertools.count(2): # Start with length=2, continue forever
|
|
for combo in itertools.product(patterns, repeat=length):
|
|
yield 'v' + ''.join(combo)
|
|
|
|
def generate_name(self) -> str:
|
|
"""
|
|
Get a fresh unique variable name.
|
|
"""
|
|
while True:
|
|
candidate = next(self._name_iterator)
|
|
if candidate not in self.used_names:
|
|
self.used_names.add(candidate)
|
|
return candidate
|