From: "Christoffer Lernö" Date: 2007-03-12T05:07:03+09:00 Subject: Re: [QUIZ] SimFrost (#117) It's interesting that it looks like everyone populated their grid using a randomizer for each position in the grid. This is is obviously fast, but for small grids (and low percentages), the percentage of actual generated vapour particles may be off by quite a bit. For a 10x10 grid and 10% vapour, the amount of particles typically range between 5 and 15, which in turn makes the finished frost look very different from run to run. I was thinking of ways to solve this. Obviously trying to randomly put vapour particles into an array - and retry if it already cointains vapur - is not ideal... My best trick is this one: require 'enumerator' percentage = 30 width = 30 height = 20 vapour = width * height * percentage / 100 vacuum = width * height - vapour grid = [] (Array.new(vacuum, ' ') + Array.new(vapour, '.')).sort_by { rand }.each_slice(width) { |s| grid << s } This gives us a grid that is guaranteed to have the correct initial proportion of vapour. Anyone else with a more elegant solution to the problem? Christoffer