The THX Sound and Random Numbers

I recently stumbled upon a 7 year old article detailing the creation of the THX sound in the 1980s. It was apparently generated by 250,000 ASP commands that were generated from a program that consisted of 20,000 lines of C code.

While entirely impressed by the work and result, this part stuck out to me.

>> There are many, many random numbers involved in the score for the piece. Every time I ran the C-program, it produced a new “performance” of the piece. The one we chose had that conspicuous descending tone that everybody liked. It just happened to end up real loud in that version.
>> “Some months after the piece was released (along with “Return of the Jedi”) they lost the original recording. I recreated the piece for them, but they kept complaining that it didn’t sound the same. Since my random-number generators were keyed on the time and date, I couldn’t reproduce the score of the performance that they liked. I finally found the original version and everybody was happy.

In visualization, I’ve come across instances in the past where I’ve needed random numbers to get a desired look, but needed repeatable results.

Take these two cases:

1.) I was re-rendering grid-like portions of a scatter-plot where data could be added but not removed. If I had 100 randomly placed points in a grid cell and needed to redraw it with 101 points, I needed the first 100 to be redrawn in the same positions they were in, plus the new one. (This one was in Flash)

2.) I was rendering a video with hundreds of thousands of “people” scattered around a floor in 3D space, but needed to be able to zoom in on particular people. If they were positioned in a truly random formation, the hard-coded positions I zoomed into would no longer show the specific people I was targeting. I needed to be able to re-render the video, position the people randomly, but have them in the same random positions they were in previously. (This one was in Processing)

For both of those cases, I came up with similar solutions. I created an alternate random() function that accepted an input parameter—a seed—and returns a random-ish floating point number between 0 and 1. For example, if you send it a seed of 123456, you might get a value back of 0.382919. If you send 123457, you might get 0.716254. What’s most important, however, is that sending 123456 again would result in the same value, 0.382919.

There are many ways to accomplish this, and I certainly didn’t set out to find the most optimal/scalable method. Within my seeded random function, I simply used the value for pi, performed some arithmetic using the seed, and returned only the digits after the decimal. That resulted in a very random-looking floating point number between 0 and 1, just like basic, non-ranged random() methods tend to provide.

In Case #1 above, I used the grid cell’s static X and Y coordinates plus the UID of the dot being rendered, and then generated a second random number with a slight variation in order to have two values—X and Y coordinates. In Case #2, all I needed was the UID of the person, also varied for a second random number to retrieve a random X and a random Y position.

As for the THX sound, they could have used a similar approach with a single hard-coded base seed value (e.g. the number 1) that is used in all subsequent seeded random function calls. This would result in the same sound being played every time. If they wanted to “compose” a new, randomized piece, the would simply change that base seed value (e.g. 1 becomes 2). To go back to a previous version, change that number back. Upon finding a composition they want to keep, simply leave that base seed in the code. The only way to lose the sound would be to lose the entire codebase, at which point your hopes of recreating the sound would obviously be slim, even if no random (or random-ish) numbers were involved.

Ludum Dare #23 48h Compo

Until Friday night, I had never heard of Ludum Dare, a global game development event celebrating its 10th anniversary. I found it via Reddit or Hacker News or Twitter or something, and discovered the event had kicked off 4 hours prior. Everyone participating in the Compo was given 48 hours to create a game from scratch around a theme announced that night. An alternate Jam competition has more relaxed rules, allowed teams, and ran for 72 hours. The theme was “Tiny Worlds,” which can be tricky when coming up with a compelling game idea. Fortunately, the theme and rules allow for pretty broad interpretation.

I wasn’t sure I would participate, but an idea popped into my head. Inspired in part by a segment of Dragon Ball Z Kai, I pondered what it would be like to jump from tiny planet to tiny planet. Mainly, what would happen to your perspective of “up” and “down” if you jump from the top of one planet to the bottom of another? The concept of “down” essentially just means “in the direction of the pull of gravity.” What drove me to want to build the game was the idea of making a 2D platformer where the directions up, down, left, and right are completely fluid and based on the gravitational pull of planets around the character.

Even though I haven’t used CoffeeScript or Processing.js before, I decided to try them out. Probably not a good idea on such a short timeline, but oh well.

The result was an auto-orienting 2D puzzle game where you have to jump from tiny planet to tiny planet to get to your goal before your oxygen runs out. You can walk around on planets and jump, but after leaving a planet’s surface, there is no longer any control over the character. That means if you miss a planet, you can drift off into space forever!

I finished an hour before the deadline and set up the game at PicoPlanets.com (a play on “pico” meaning one one-millionth, or 0.000001) and made the source code available on GitHub. You can also see screenshots and blog posts about the progress (“making of”) here on my Ludum Dare author page.

R.I.P. Kerplunk 2008-2009

A few years ago, I put together an alpha version of an AIR-based Twitter desktop client, called “Kerplunk!” It deserved its alpha status. It was little more than a proof of concept, focusing solely on displaying a new way of looking at and interacting with streams of tweets. I ran out of time and momentum on the project in mid-2009 and never got around to updating it while the Twitter API evolved (OAuth, id_str, etc).

If I had that primitive alpha version of Kerplunk! today, it would still be able to improve my Twitter experience. Twitter has only gotten noisier, and Kerplunk was the only application to provide ways of suppressing certain types of content—craptweets—either partially or entirely. To deemphasize craptweets, Kerplunk! would simply reduce the screen real estate available for that tweet and truncate it after a certain number of characters. If it turned out to be interesting, despite tricking Kerplunk! into thinking it was crap, you could still spot it and expand it. Simple, yet amazeballs. I miss it.

What’s more, Kerplunk! was designed from Day Zero to go beyond Twitter (in fact, the core application included ZERO references to Twitter or tweets, aside from a command to download and install a plug-in called “Twitter”). You see, I don’t give a damn about tweets or Twitter. I care about what my friends are posting and sharing online, be it on Twitter, Facebook, blogs/RSS, etc.

While the prototype source code lay abandoned collecting dust, the idea and desire remained. The idea grew beyond Kerplunk!, though. Beyond a desktop application, at least. Since 2009, I’ve used my phone more and more to see what my friends are up to, probably up to 50% of my social media usage. I also came up with concepts that would benefit from my application to talk directly to another application, rather than communicating only through social network APIs.

The nice thing about ideas is that they can evolve and change entirely. Over the last 3 years, I’ve wanted different tools to solve different problems I had with my disparate social graph. Kerplunk! evolved into something else entirely. I’ll share what the new project is all about in a subsequent blog post. Stay tuned!

Homeless for a year

Here's @brianshaler waiting for the train. PLEASE hope w... on Twitpic (looks like Twitpic isn’t working right, and I can’t download and upload their photos via my phone.. I’ll try to fix the image when I’m not restricted to my phone)

I didn’t set out to last any specific amount of time. I thought 6-12 months of full-time travel—the much more glamorous way of saying homeless—was doable, considering I had already spent a few years traveling part-time while working. On a few occasions, I had used my 1-week carry-on bag to last 4 or more weeks. I figured as long as I could find a way to do laundry every week, I could travel indefinitely.

The core of the experiment was about living expenses and sustainable travel. Traveling, even on a tight budget, is very expensive. The cost of food, lodging, and transportation while traveling can easily match or exceed your standard cost of living. Full-time travel could thus double your monthly expenses. But what if you were able to eliminate the first part of the equation and only pay living expenses wherever you currently are? What if you could go to Rome for a month and not have to pay for the month of rent and utilities back home?

To keep travel cheap, on a per-day calculation, you need to travel slowly. Going to another continent for one or two weeks results in a very high per-day cost, but you can save on lodging by staying longer (weekly rates are lower than daily rates, and monthly rates are lower than weekly rates) and lower the per-day cost of transportation by putting more time in between flights.

I decided a year ago to try this out. I rented a studio in the Bahamas for 35 days for $600, a room in DC for 4 weeks, a hotel in Germany for a month (which was thankfully reimbursed by a client), a hostel in Budapest for 3 weeks, a mountain-top hotel in the US Virgin Islands for 3 weeks, and a cabin in lower Manhattan (which I had to see to believe) for 5 weeks.

So, 6-12 months. When will it end? When will I “settle down” and return to traveling only part-time, 1-3 weeks per month? It’s an internal conflict I’ve had since the 6th month. The full-time travel is exhausting, stressful, and both physically and mentally taxing. But at the same time, I’m in a position to travel longer and farther than I would otherwise be unable to. Giving up now would feel like squandering the unique opportunity I have. I have never been to Asia, Australia, Africa, or South America, and this would be a great time to do it.

The jury is still out. It could be up in the sky, for all I know. Speaking of which, I am now on my descent into Charlotte, North Carolina. Time to turn off and stow all portable electronic devices.

“Finally, a REAL Hungarian man”

image

I was hanging out with a new friend I made in Budapest, via Twitter no less. A homeless guy approached us, stood in front of me and started speaking in Hungarian. My friend stepped in, speaking Hungarian to the man, gave him some change, and then the man left. My friend translated what the man had said to me. “Finally, a REAL Hungarian man!” My friend set him straight. Just a funny looking American.

In Hungary, almost every person on their paper currency features some sort of facial hair. Most of the statues, too, don mustaches and beards.

My handlebar mustache was uncommon among the people there,but it seemed to fit right in with their money and art. Their history.

I was a blast from the past.