Re: Random list of filenames
- From: William James <w_a_x_man@xxxxxxxxx>
- Date: Sun, 29 Jul 2007 21:07:41 -0700
On Jul 29, 8:24 pm, Rob S <Here@home> wrote:
Thank you all. The awk script was where I was heading when I got stuck.
All 3 scripts work well, but the ruby script was ideal. A good
assortment, equal number in each list, and lightning fast, all of 2
seconds. beautiful.
I think it's about time I tried drumming ruby into my old grey matter.
Cheers all.
--
Rob
Ruby is very nice. You don't have to create any
classes if you don't want to; you can use it much
as you would use awk or Perl.
I'm afraid that my code didn't do a
perfect job of evenly distributing the files.
This version is probably correct.
#!ruby
list = Dir[ "*" ].sort_by{ rand }
chunk, remainder = list.size.divmod( 4 )
start = 0
4.times{ |i|
amount = chunk
if remainder > 0
amount += 1
remainder -= 1
end
File.open( "__list_#{i}", "w" ){ |f|
f.puts( list[ start, amount ].sort )
}
start += amount
}
.
- References:
- Random list of filenames
- From: Rob S
- Re: Random list of filenames
- From: William James
- Re: Random list of filenames
- From: Rob S
- Random list of filenames
- Prev by Date: Re: IP addresses to countries
- Next by Date: Re: IP addresses to countries
- Previous by thread: Re: Random list of filenames
- Next by thread: Re: Random list of filenames
- Index(es):
Relevant Pages
|