Skip to content

Commit

Permalink
Add comments about magic numbers (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
kojiwell committed Apr 25, 2022
1 parent e412cdd commit 78dbea7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/trops/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ def tranquility():
def generate_sid(args, other_args):
"""Generate a session ID"""
s = tranquility()
# Three is a magic number
hlen = 3
tlen = 4
n = randint(0, len(s)-hlen)
now = datetime.now().isoformat()
head = ''.join(list(s)[n:n+hlen]).lower()
tail = hashlib.sha256(bytes(now, 'utf-8')).hexdigest()[0:tlen]

# Seven is also a magic number
print(head + tail)

0 comments on commit 78dbea7

Please sign in to comment.