On Fri, Nov 13, 2009 at 3:43 PM, Paul Smith <paul / pollyandpaul.co.uk> wrote: > On Fri, Nov 13, 2009 at 3:31 PM, Haoqi Haoqi <axgle / 126.com> wrote: >> hello,happy weekday! >> in ruby1.9: >> irb:> >> %w{ruby c java php}.permutation.to_a >> >> and my code is(all ruby): >> irb:> >> (1..1000).inject([]){|p,_|p<<%w{ruby c java php}.sort_by{rand}}.uniq > > .shuffle! is shorter than .sort_by{rand} by 5 characters. > > I hate that your method is nondeterministic, but I've got it spinning > in a while loop and having broken it yet... And it just did. FWIW, your method only gives the correct result with probablity 1 - ((23/24)^999) so it should fail once every 2.9 trillion runs (3x10^18). > -- > Paul Smith > http://www.nomadicfun.co.uk > > paul / pollyandpaul.co.uk > -- Paul Smith http://www.nomadicfun.co.uk paul / pollyandpaul.co.uk