import random import csv def data_preparation mac_qnt ding_nt elements

 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
import random
import csv
def data_preparation(mac_qnt, ding_nt):
elements = {}
macs = [f'{random.randrange(0, 10000, 1)}_mac' for count in range(mac_qnt) ]
for index, value in enumerate(macs):
first_bit = random.getrandbits(32)
elements.update({value:[f'{first_bit}_{item}_id' for item in range(ding_nt)]})
print(elements)
return elements
def create_csv(elements):
l1 = []
with open ('new_csv_file.csv', 'w') as csvfile:
fieldnames = ['mac', 'ding_id']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for mac, ding in elements.items():
for val in ding:
l1.append({'mac':mac, 'ding_id':val})
random.shuffle(l1)
writer.writerows(l1)
create_csv(data_preparation(10,100))