forked from JoepdeJong/trustchain-double-spending-scores
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddresses.py
74 lines (61 loc) · 1.97 KB
/
addresses.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import random
import sys
def generateAddress(length = 148, seed = None):
"""
Generate a hexadeximal address
"""
if seed is not None:
random.seed(seed)
address = ""
for i in range(length):
address += str(hex(random.randint(0, 15)))[2:]
return address
def generateScore(seed = None):
"""
Generate a random double spending score between 0 and 1
"""
if seed is not None:
random.seed(seed)
return random.random()
def createAddressList(length = 100, input = "input-addresses.txt"):
"""
Create a list of random addresses with random scores
"""
addresses = []
n = 0
# Check if the input file exists
if os.path.isfile(input):
# Read the addresses from the input file
with open(input, "r") as f:
for line in f:
addresses.append((line.strip(), generateScore()))
n += 1
for i in range(n, length):
addresses.append((generateAddress(), generateScore()))
return addresses
def writeAddressList(addresses, output = "output-addresses.txt"):
"""
Write the list of addresses to a file
"""
with open(output, "w") as f:
for address, score in addresses:
f.write(address + " " + str(score) + "\n")
if __name__ == "__main__":
# Set default values
length = 128
seed = 1337
# Read input from the command line
# The first argument is the number of addresses to generate, the second argument is the seed
if len(sys.argv) > 1:
length = int(sys.argv[1])
if len(sys.argv) > 2:
seed = int(sys.argv[2])
else:
length = 128
# Create a list of random addresses with random scores
addresses = createAddressList(length)
# Set the output file name in the format "output-addresses-<seed>-<length>.txt"
filename = "output-addresses-" + str(seed) + "-" + str(length) + ".txt"
# Write the list to a file
writeAddressList(addresses, filename)