One of my hobbies is quilting, and recently I've been preparing fabric scraps for a scrap quilt. When I am finished collecting and cutting, I will have 168 six-inch squares of distinct fabrics. My plan is to sew them togther in a 12 by 14 block grid.

Out of curiosity, I want this quilt to be as random as possible, and I was puzzling over a way to eliminate my human bias for color coordination (or lack thereof) when selecting block positions. Suddenly, it hit me: Perl.

I bolted into #perlmonks and with the help of the excellent monks there, this perl quilt generator was created.

A few words about logistics - each fabric swatch will be labeled, from 1 to 168. To keep this as random as possible I think I'll probably put all the swatches in the dryer and let them be tossed around for a few minutes, then pull them out one at a time to assign their number. The perl script below will produce a grid of numbers, and the numbers represent the swatch with that number.

A round of perl golf also ensued, but I'll let the participants in that post their own code. Here's what I ended up with (with a lot of help from my friends.)

#!/usr/bin/perl -w use strict; ### # the perl quilt generator # concept by ailie, perl created with the great help of jlp, jcwren, # japh, neshura, mikfire, and all of #perlmonks ### my @swatch; my @quilt; @swatch=(1 .. 168); while (@swatch) { my $x = rand(@swatch); my $v = $swatch[$x]; push(@quilt, $v) && splice(@swatch, $x, 1); } print join(" ", splice(@quilt, 0, 12)) ."\n" for (1..14);