The Code Diarist

A diary about code

Randomness Completes a Patchwork

April 24, 2025

Pick a start. Any start. Memorize it. Put it at the beginning. Go from there.

Selecting words randomly can overcome writer's block, where the first sentence or paragraph refuses to reveal itself. Somehow, now, I have to relate that thought to making a quilt.

Dear Code Diarist: how does making a craft item relate to code?

Procedure is the answer. Assembling a quilt gives a good example of following a procedure. Random selection can figure into the answer also.

Quilt patterns abound, collected by the hundreds and thousands in books and magazines. My half-dozen or so quilt books, alone, identify more than 5,000 different blocks, or patterns for a project. Each of them can be assembled in limitless combinations of fabrics and colors. Which one to choose? Stop thinking about it! Random selection is an antidote to paralysis by analysis. Throw a dart at the list from across the room. Get the point? <chuckle>

Assembling a quilt usually settles into a highly procedural flow of work. Cut so many of these pieces and so many of those. Sew them together in a certain order. Press one seam to the left, the next to the right, and so forth. Similarly, code written for programmable devices consists entirely of data structures and procedures, organized into blocks of code.

Random selection comes into play a second way when I wish to scramble the visual elements around somewhat in a quilt. But here, actual computer code may be needed.

Suppose my quilt has 99 blocks, arranged in a rectangular grid having 11 rows of 9 blocks each. Of these blocks, 17 are light while 82 are dark. The idea is to scatter the 17 around randomly among the rows and columns.

Nature does this with wildflowers along a roadside easily enough. But when I try to mimic Nature this way, the result too often looks intentional. And that is because human beings are wired to impose patterns on Nature.

The way to get randomness into a quilt is with a random number generator. A pair of 10-sided dice works well for the example here. Each die has sides numbered 0 through 9. Roll two of the 10-sided dice to get numbers from 00 through 99.

As I put the quilt together, joining one block to the next, roll the the dice to pick each, next block in succession. If the number is less than 17, pick a light-toned block. Otherwise pick a dark-toned one.

A strict procedure like that qualifies as a kind of Code in the sense of being a set of rules to follow. It is also a method for using calculations to solve a problem, which is more or less what computer code does for a living.

It may need a good computer program to generate the random numbers when a quilt calls for more elaborate randomization. I do not go into details here about writing that kind of code. Let us allow an example to illustrate the benefit of it.

I recently quilted a bedspread for a niece who will turn three soon and graduate onto a twin-sized “big-girl” bed. It is a quilt of many colors that, while organized in a geometric layout like a formal garden, needed to be randomized at a smaller level of detail.

Think about those wildflowers again. It ought to look as though Nature had arranged the colors on that quilt. A program produced many different combinations of 7 colors selected randomly from a set of 13 distinct colors. Each combination received a unique identifying number. Then the combinations were selected randomly, two different ones for each block in the quilt, in such a way that no pair of color combinations was used more than once.

The result is very satisfying, as the 13 colors spread out across the quilt in seemingly endless variety. I could never have achieved that result by myself, by eye.

There, now. You have a diary entry about a patchwork quilt that needed code to complete it. And I reached the end from a randomly selected starting sentence about selecting words randomly.

Go to your room, Code Diarist, and stay there until you are ready to wipe that smirk off your face and come out and behave yourself!