Random Writing with WolfLang: Breaking Through Writer’s Block with the Wolfram Language

Random black keyboard keys scattered around
Photo by Sofia on Unsplash

The blank page, bane to any writer!

If you’re trying to write a story, be it for National Novel Writing Month or just for fun, you’ll have to face a blank page eventually. The seeds of an idea can help your story grow, blooming into a sweet rose of romance or a carnivorous tale of horror. Without those ideas, all that’s left is a blinking cursor… and frustration.

Photo of a group of Venus flytrap plants
Photo by Andi Superkern on Unsplash

If you’re stuck on what to write, maybe a little randomness can help. Using some of the Wolfram Language’s Random functions, you can brainstorm ideas, pull from image prompts, create mood boards and even chart the rise and fall of a plot.

Ready? Let’s write!

Getting Our Setup: Genre and Subject

What genre are we writing in? Genre is a way of framing ideas, featuring useful tropes we can use or deconstruct. To get a genre, let’s fill up a word list with some genres we enjoy writing. We can then pick one at random with RandomChoice.

Here is what we’d type for a choice among sci-fi, fantasy and horror, as well as the random result:

Screenshot of RandomChoice with genres as list options

What is our story about? Let’s use ResourceFunction[“RandomWikipediaData”][] to pull up a random Wikipedia page.

Random Wikipedia snippet from the Sherborn page

Hm. That’s okay, but if we reevaluate the function, maybe we’ll find something better.

Random Wikipedia snippet regarding a fjord in Greenland

Yes! Who doesn’t love a fjord?

Photo by Annie Spratt on Unsplash

Note that, once we have the function, we can highlight the cell and evaluate it over and over until we get an inspiring result. (Or you could write on hard mode and use whatever result you get, even if it’s the bio of an obscure Polish shoemaker.)

If you’re not inspired through the RandomWikipediaData function, you can get some more ideas through a random list of words with ResourceFunction[“RandomText”][3].

Random text function showing “signalization,” “anchorage,” and “sulkiness”

Two friends travel to Greenland, and due to mixed signals, they have a falling out, resulting in sulkiness once their boat’s anchor malfunctions….

A sulky scientist sets up anchorage at a fjord and finds an unusual signal….

Once you’ve gotten an idea or two, you can find your story’s theme by changing the number at the end of the function to [1]. This will show a single, thematic word.

Let’s try it. Our theme is…

Random text function showing “purse”

Not your typical theme, but perhaps it’s a metaphor for hidden depths. The sulky scientist isn’t so one-dimensional after all!

Visualizing the Story with Random Images

Having words in mind is good, but another way to keep the ideas flowing is to use random images. There are several random image functions available, so let’s try one and see what happens.

If we type in ResourceFunction[“GetLoremFlickrImage”][], we can get a Creative Commons–licensed image.

Random image showing a gray striped cat on a red blanket with a red background

If there’s an internet, there’s a cat. Guess the scientist has a feline friend. At least the fjord has plenty of fish.

Images can help with all sorts of visualizations. For example, if there are people in the images, they can act as friends and enemies (to lovers). If there’s a location, it can be a scene in our story. A random object can act as a MacGuffin or a Chekhov’s gun that will ramp up the story’s tension.

How about looking at the story as a whole? Using ImageAssemble[Table[ResourceFunction[“RandomPhoto”][150, 150], 3, 3]], a function that gives us nine random photos arranged in a table, we can create a mood board. Mood boards, like theme and genre, reflect the story’s core ideas and reader expectations.

Screenshot of several random images displayed in a square, as if a mood board

It’s a bit of work to connect the images, but there’s bleakness, prickliness, open water and looking up from the depths. There’s no horror just yet, but the middle-left image has promise when compared to the swimmer at the bottom.

Note that by priming the story with the previous random prompts, it’s easier to see where this mood board might connect with those initial seeds. This same set of random images could just as easily skew toward a rom-com where a surly, high-achieving businessman moves back to his hometown by the sea, only to discover a special someone who drops a stack of mysterious letters….

What a Character!

Now that we have an idea of where and what our story is, let’s figure out who the story is about.

Let’s name our characters with ResourceFunction[“RandomPetName”][], which will give us a random name. If we run the function in two different cells, we can get two random names at the same time:

Screenshot of two random name functions, with the names “Flora” and “Salem Adams”

Salem Adams, sulky scientist, and Flora, feline first officer, star in a tale of horror as they investigate a mysterious signal from the depths of Greenland’s fjords….

Random functions aren’t just good for naming your characters: they can describe what your characters do. Say you’re writing a romance. What’s your love interest’s job? Run the ResourceFunction[“RandomPretentiousJobTitle”][] function to find out.

Random job title function showing “Chief Research Planner”

For all the sci-fi writers, let’s throw in an alien name for fun. Use ResourceFunction[“RandomString”][] to create a random string of letters. Put a number in the brackets for a specific number of letters.

Random text string, showing “ulbtmh”

His friends call him Ulb. His enemies never even learn his name….

Hey, Plot, Where Are You Going?

At this point, your fingers might be flying over the keys, drawn into this random story. But what’s the shape of your story?

There are so many ways to look at narrative and story structure. There are five-act stories that have a rise and fall. There’s the monomyth, which cycles through patterns and archetypes. There are narratives that loop and reshape themselves around characterization, focusing on snatches of time.

We’re going to let Graphics[BezierCurve[RandomReal[1, {5, 2}]]] — a function that draws a random Bézier curve through a certain number of points in a certain area of space — tell us the path of our plot. Maybe it’s the level of excitement in our narrative. Maybe it’s character growth over time. Either way, we can use the random path as inspiration.

Let’s see some examples…

Random curve going upward

Nothing happens on the placid water, and after a brief scare one night, life seems to go back to normal for Salem and Flora. Then things go haywire, and the story ends with high tension and high stress, typical of horror.

Random curve going bleakly downward

Salem is about to lose his grant funding, and he’s hoping that the fjord trip will result in something big. Too bad he gets his wish, ending up at a lower point than when he started.

Random curve zagging upwards

Flora’s path to self-actualization truly begins after she stops holding herself back and realizes that her scientist was doomed from the start. Fjord monsters like cats too….

Feel free to change the numbers and see what happens. If you want to dive deeper into random scribbles, check out this explainer, which explores all the parts of the function and takes you into the 3D space. (How might that change your story’s plot structure? Perhaps converging narratives?)

Mad Libs, for When You Don’t Know What to Write

Say you’re at a rough patch, and you’re not sure where the story should go. Maybe you’re even at the home stretch, but you can’t think of a way to end things.

Like with the word lists and single random words for theme from earlier, you can get random words through the RandomWord function. Even better, you can request only certain types of words, such as nouns, verbs or adjectives. In this sense, we can use Mad Libs–style random words to complete part of our story.

First, let’s create the blanks of our Mad Libs, which will all be designated by variables. We’ll give them easy names, like adj1, adj2 and so on.

Here’s a random list of words, with those words assigned to variables:

Screenshot showing a list of variables, followed by a list of random words

That’s interesting, but how can we use these words? We can create a template ending and insert our variables, giving us human-readable text on output. To do that, we’ll use the StringForm function.

Here’s a sample snippet of code:

StringForm[“He was ``. After all that had happened, and with everything so ``, he felt like ``ing off into the sunset. So he did, ``, with `` in hand. \”Time to ``, I guess,\” he said. He had learned about ``. The end.”, adj1,adj2,verb1,adv,noun1,verb2,noun2]

Note that you can use tick marks (``) to mark places for your variables. If you use quotation marks in your text, be sure to add a backslash (\) to keep them!

The end result:

Screenshot of text reading as follows: “He was gelatinous. After all that had happened, and with everything so unpublishable, he felt like choiring off into the sunset. So he did, cagily, with decryption in hand. “Time to please, I guess,” he said. He had learned about maxilla. The end.”

“Unpublishable,” you say? Hm.

Oh, well. At least we had fun. That’s what random writing is all about!

About the blogger:

Jesika Brooks

Jesika Brooks is an editor and bookworm with a Master of Library and Information Science degree. She works in the field of higher education as an educational technology librarian, assisting with everything from setting up Learning Management Systems to teaching students how to use edtech tools. A lifelong learner herself, she has always been fascinated by the intersection of education and technology. She edits the Tech-Based Teaching blog (and always wants to hear from new voices!).

--

--

Tech-Based Teaching Editor
Tech-Based Teaching: Computational Thinking in the Classroom

Tech-Based Teaching is all about computational thinking, edtech, and the ways that tech enriches learning. Want to contribute? Reach out to edutech@wolfram.com.