removed useless file
[qmc.git] / shuffle.lua
blobd8b3b38a3532886855e124a4eec40eeb95da0707
1 #!/usr/bin/lua
3 local fn = ...
5 local it = setmetatable({}, { __index=table })
6 --local ot = setmetatable({}, { __index=table })
8 local f = assert(io.open(fn, 'r'))
9 local l = f:read()
10 while l do
11 it:insert(l)
12 l = f:read()
13 end
14 f:close()
16 print('read\t '..tostring(#it)..' lines')
18 for i = 1, #it do
19 local j = math.random(i, #it)
20 it[i], it[j] = it[j], it[i]
21 io.write('shuffled '..tostring(i)..' lines\r')
22 io.flush()
23 end
24 print()
26 local f = assert(io.open(fn..'.shf', 'w'))
27 for i, l in ipairs(it) do
28 io.write('written\t '..tostring(i)..' lines\r')
29 io.flush()
30 f:write(l..'\n')
31 end
32 f:close()
34 print('written\t '..tostring(#it)..' lines')