-
Notifications
You must be signed in to change notification settings - Fork 4
/
generate_data.rb
38 lines (32 loc) · 959 Bytes
/
generate_data.rb
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
require 'json'
COMMON_RANDOM = Random.new(2310)
# return an array of the integers between 1+ofs and n+ofs
def data_sorted(n, ofs=0)
((1+ofs)..(n+ofs)).to_a
end
# return an array of the integers between 1+ofs and n+ofs in reverse order
def data_reverse(n, ofs=0)
((1+ofs)..(n+ofs)).to_a.reverse
end
# return an array of the integers between 1+ofs and n+ofs in random order
def data_random(n, ofs=0)
((1+ofs)..(n+ofs)).to_a.shuffle(random: COMMON_RANDOM)
end
# return an array of size n where blocks of size bs are independently shuffled
def data_nearly(n, bs, ofs=0)
a = []
for i in 0..n/bs-1
m = [bs, n-a.size].min
a += data_random(m, i*bs+ofs)
end
a
end
data={}
for n in [100, 200, 400, 800, 1600, 3200, 6400, 12800] do
ndata={}
ndata["random"] = data_random(n)
ndata["reverse"] = data_reverse(n)
ndata["nearly"] = data_nearly(n, 100)
data[n] = ndata;
end
File.open("generated_data.json", "w+") {|f| JSON.dump(data, f)}