From: James Edward Gray II Date: 2007-03-27T03:04:41+09:00 Subject: Re: Housie (#114) On Mar 22, 2007, at 8:58 PM, Quest Lee wrote: > rretzbach's first proposal is exactly the same as mine. I don't > think the > probabilities are not evenly > distributed in the proposed. And my program generates the row > pattern is the > following: > > def make_rows > row1 = gen_rands_nodup(9, 0, 5, Array.new) > row2 = gen_rands_nodup(9, 0, 5, Array.new) > row3= [0,1,2,3,4,5,6,7,8]-(row1+row2) > row3 = gen_rands_nodup(9, 0, 5, row3) > end > > > def gen_rand max,range > rand(max) + range * 10 > end > > def gen_rands_nodup max,range,num,arr > i = arr.length > while i < num do > rand_val = gen_rand(max,range) > while arr.include?(rand_val) do > rand_val = gen_rand(max,range) > end > arr[i] = rand_val > i += 1 > end > arr > end > > Is there any bug in this algorithm? I don't think so, but it's a little hard to follow the logic. You could definitely simplify gen_rands_nodup using upto(), times(), or inject(). I would begin by trying to remove the index. I'm not immediately sure how to prove it's not purely random, though my hunch is that it is not. James Edward Gray II