-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen_data.py
39 lines (26 loc) · 1.06 KB
/
gen_data.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
import random
def gen_random_data(num_lines=100, max_line_length=1000, max_coordinate=10000, file=""):
min_y = 0
max_y = max_coordinate
lines = []
for _ in range(num_lines):
line = []
min_x = 0
max_x = max_coordinate
line.append((0, random.randint(min_y, max_y)))
for i in range(random.randint(2, max_line_length)):
line.append((random.randint(min_x + 1, max_x - 1), random.randint(min_y, max_y)))
if line[-1][0] > (max_x / max_line_length) and line[-2][0] > (max_x / max_line_length): break
min_x = line[-1][0]
if min_x == max_x - 1: break
line.append((max_x, random.randint(min_y, max_y)))
lines.append(line)
if file:
with open(file, "w") as fout:
print(num_lines, file=fout)
print(file=fout)
for line in lines:
for p in line:
print(str(p[0]) + ',' + str(p[1]), file=fout)
print(file=fout)
return lines