randomness

READ: the chapter on Randomness from the book 10 PRINT CHR$(205.5+RND(1)); : GOTO 10 (the title of which is the algorithm implemented in the language Basic).

The allure of gambling—and more generally, the allure of chance in all games—rests on uncertainty. Uncertainty is so compelling that even otherwise skill based games usually incorporate formal elements of chance, such as the coin toss at the beginning of a football game. As Katie Salen and Eric Zimmerman put it, uncertainty “is a key component of meaningful play” (2004, 174). Once the outcome of a game is known, the game becomes meaningless. Incorporating chance into the game helps delay the moment when the outcome will become obvious.

from Randomness (10 PRINT CHR$(205.5+RND(1)); : GOTO 10)

Among the many examples of "chance" and "randomness" in the history of art discussed in the assigned chapter are:

Those involved with the composition of experimental music find ways and means to remove themselves from the activities of the sounds they make. Some employ chance operations, derived from sources as ancient as the Chinese Book of Changes, or as modern as the tables of random numbers used also by physicists in research”

John Cage

There is this old romantic idea which is called "intuition". An artist has talent, a genius, sits down, has a drink and creates. And intuition does what it does, sometimes it creates something good, sometimes not. Now, when we work with computers we're modern and say intuition is old fashioned, I'm not interested. But there is a thing that can replace intuition. It's randomness.

Vera Molnár

In this next section we'll learn how to program by learning to code in the Web's defacto programming language: JavaScript. I'll be introducing all the core concepts in programming through the lens of "creative coding", and more specifically through the lens of "randomness" or "chance", using JavaScript's built-in randomness function Math.random()



NOTE: Rather than using the normal forward and backward slashes, we'll be using other slash characters from the Unicode Standard, specifically the and .





JavaScript



In the book, the programming language used to create the 10print composition is BASIC, this language was incredibly popular for many years (including among artists, especially in the 1980s) but is no longer considered a very modern language. Today, there are loads of different programming languages out there, they all basically do the same thing: allow you to write programs that get the computer to do what you want it to do. All programming languages contain the same core concepts (variables, functions, loops, conditional statements, etc) but they all have slightly different ways of expressing these concepts, which is to say, they all have different syntax and APIs. Although any solid programming language could be used for anything (whether you're creating a website, or an iPhone app, or a video game, or a robot) some languages have special features that make them better suited for certain contexts or tasks. Different languages also have different communities of developers writing libraries and frameworks for that language.

Although JavaScript is not the only programming language we can use on the Internet, it's definitely the most popular, which means there's a large community creating libraries, tutorials and answering questions online. Furthermore, although JavaScript can be used for everything from controlling robots to scripting PhotoShop, it was originally invented as a programming language for the Web specifically, and so it's obviously the natural choice for us.

[Netscape, 1995] displayed Web pages that were not very lively. You could have a nice cartoon of a monkey on the Web page, but there was no way to make the monkey dance when you moved over it with your mouse. Figuring out how to make that happen was the job of a language developer named Brendan Eich. He sat down and in a few weeks created a language called JavaScript [...] as browsers proliferated and the Web grew from a document-delivery platform into a software-delivery platform, JavaScript became, arguably, the most widely deployed language runtime in the world. If you wrote some JavaScript code, you could run it wherever the Web was—everywhere.

Paul Ford, from What Is Code in Bloomberg Business (2015)




Homework / Review

Here is the basic 10print algorithm written in JavaScript which we created in class, and here is the animated version. Below you'll find interactive examples where you can review all of the core programming concepts we covered in class with netnet, and for folks who are already well versed in these core concepts, I've preparred some more advanced notes on how to write variations on 10print as a way of learning more about JavaScript's "expressive" syntax.

the ingredients

If algorithms are like recipes, the data we store within variables are the ingredients

declaring variables
reassigning variables
simple data types
data structures: Arrays
data structures: Objects

the instructions

conditional statements, functions (sometimes called methods or routines) and loops are how we "control the flow" of the instructions that make up our algorithmic recipes

conditionals (if, else)
functions (aka methods)
loops (for, while)

For a more thorough review these core programming concepts as they appear in the JavaScript language, consider reading the first few chapters from Marijn Haverbeke's book Eloquent JavaScript (3rd edition 2018) as well as the Mozilla Developer Network's JavaScript language overview.