-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_storage.py
31 lines (26 loc) · 881 Bytes
/
user_storage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import random
import string
uuid_length = 64
uuids = []
# generate random uuid
def generate_random_uuid(length):
characters = string.ascii_letters + string.digits
random_uuid = ''.join(random.choice(characters) for _ in range(length))
return random_uuid
# get numbers from uuid (for request routing to distinct server request handling thresholds)
def get_uuid_nums(uuid):
res = ''
for c in uuid:
if c in string.digits:
res += c
if res == '': return 0 # rare edge case -- all 64 characters are chosen from 'string.ascii_letters'
return int(res)
# handle adding users
def add_users(n):
for i in range(n):
uuids.append(generate_random_uuid(uuid_length))
# handle removing users
def remove_users(n):
for i in range(n):
removal_index = random.randrange(len(uuids))
uuids.pop(removal_index)