Skip to content

Ecce Signum

Immanentize the Empathy

  • Home
  • About Me
  • Published Works and Literary Matters
  • Indexes
  • Laboratory
  • Notebooks
  • RSS Feed

Procedural Generation 1 – Creating a Cave using Cellular Automata

2011-11-01 John Winkelman

Cellular Automata rule sets are quite useful for building cave-like systems.

  1. Fill a bitmap with random black and white dots. Black represents filled space, white represents open space.
  2. Iterate through the bitmap, applying the CA rules to each pixel
  3. create the updated bitmap
  4. cycle back to step 2, repeat until desired result

The following is the series, from random noise all the way to a completed cave system. Each image is 64×64, though it can easily be scaled up to any arbitrary size. I have found that images at 256×256 and above tend to bog down somewhat, so be careful.

Once you have tweaked the algorithms to get the desired cave design, you may have more than one disconnected piece. There are three ways you can re-connect those pieces to the cave system

  1. go through and eliminate all but the largest open area
    – This might result in a quite small cave, so some experimentation here might be necessary, such as setting an arbitrary number of pixels or percentage of overall area as the minimum allowed cave size
  2. draw tunnels to connect the pieces
    – either find the center point of each piece, and draw a tunnel from point A to point B, or iterate through each point in each open area, find there they are closest together, and connect those points
  3. in multilevel games, connect to the next level(s) up and down. A cave needn’t be only one level.
    – this assumes that the same issue does not exist in the next level up and/or down. An unfortunate selection of initial starting conditions could result in two “silo” caves next to each other, with few or no connection points.

There will be some back and forth between tweaking the algorithm and deciding what makes for the best caves. You can add logic to sometimes eliminate extra rooms, sometimes connect them, and sometimes connect them to the next level.

Of course, you don’t necessarily need to create all of the levels at load time. You can create them on the fly – though this does make vertical connections more difficult. Do some experimenting; see which method works best for you. I suggest always having at least two lower levels created, to reduce potential conflicts when fleshing out the current level.

Posted in ProgrammingTagged procedural art comment on Procedural Generation 1 – Creating a Cave using Cellular Automata

Exploring the Primal Blueprint

2011-11-01 John Winkelman

For about eight months now I have been following a diet and lifestyle plan called the Primal Blueprint. It has many dedicated followers and fervent advocates. Actually, rather than “follow” I would say I fly in loose formation with the Blueprint. I have my lapses – being only human, and living around the corner from one of the best bakeries in the city. Still – my health and fitness levels are much improved, and despite the occasional bag of potato chips for dinner, things continue to improve on a gradual and manageable trajectory. I can fit into clothes that last buttoned in my early 30s, if not earlier. My weight hasn’t been this low, I think, since I began building websites for a living.

I have never been one to follow “a diet”. The path that took me to where I am now follows:

Back in 2007 my brother, his future wife and I road-tripped to Louisiana to visit our dad and spend some time wandering around Mardi Gras. We had a splendid old time, ate tremendous amounts of really good food, and got to enjoy New Orleans when it was bearably hot and humid. Every day brought a new delicacy, and it being Mardi Gras time, we went through at least one full King Cake every day. Add to that all the deep-fried southern delicacies, gallons of beer from the Abita Springs brewery less than a mile from Dad’s house, and, well, a lot more of me came back from vacation than started out.

I didn’t really feel like I had gained weight. My clothes were tight, and I had to let out my belts a notch, but I told myself it was just the winter hibernation metabolism doing its thing. I bought a bathroom scale, found out I weighed around 205 pounds. It didn’t seem like such a big deal; as a martial arts instructor I work out a lot; up to fifteen hours a week in class, plus all my personal training. Still, 205 seemed kind of high.

Thinking back through the list of food on the vacation, talking to my girlfriend, I realized I couldn’t name a single vegetable I had eaten, other than those in the buckets of gumbo or chili, or french fries, or onion rings. That made me feel kind of queasy.

I immediately drove to the store and bought a car-load of fresh (-ish; they were from a grocery store) vegetables and fruit, and started packing bowls of chopped up tomatoes and avocado for lunch at work. This represented a big change from my usual habit of ordering a sandwich nearly as big as my head from the amazing kitchen at Founders Brewing Company, which at the time was one floor down from where I worked. In a surprisingly short amount of time, the weight began dropping off. For a while, it seemed like every other day I would weigh myself and I would have lost another pound. By the beginning of May I was approaching 190. That was when the Fulton Street Farmer’s Market opened for the year. Suddenly I had vegetables in abundance.

At about that same time my girlfriend put herself on a restricted diet, which cut out all refined sugar, corn syrup and wheat gluten. Have you ever tried going out to eat, or buying common snack foods, without getting at least one of those three ingredients? Not easy at all. Here is where I had to begin adding new tools to my intellectual toolkit. Namely, cooking. A random bowl of raw vegetables is perfectly acceptable for a lunch for one, but when it comes to full meals with a significant other, it quickly gets old.

Between the internet and my girlfriend’s stash of vegetarian and vegan cookbooks, we built up a reasonable repertoire of yummy recipes. For me, the weight continued to fall. I got down below 190 for the first time in who knows how long. Finally, I stabilized around 185, with one noticeable dip down close to 180 during a serious bout of the flu.

Life was good. Then I got complacent. Then the weight started creeping back, a pound at a time. Work- and life- related stress made things worse. Over the next year and a half I returned to 195, where my weight stabilized, though a hard weekend of pizza and beer could bring it back up close to 200. And here I stayed until roughly February 2011.

As is usual at the turning of the lunar new year, I had made a few goals for myself. Not resolutions in the sense that I wanted to accomplish this and that and the other thing. More like, these few important things in my life, I want to do a little better. Of course my weight was one of those things.

I don’t remember how I discovered Mark’s Daily Apple, but I had been reading it for a few months. He seemed to really know what he was talking about, and backed up everything with scientific research (from actual scientists, no less!), statistics, and anecdotal evidence from himself and others of a similar mind-set. And his website is the hub of a community of happy, healthy, motivated people.

Anyway: Chinese New Year came and went, it was now the Year of the Rabbit. And I read the story of the Unconquerable Dave. Take a minute to read this one. It is really something.

Re-inspired, I cut way back on the grains and legumes, and ramped up the meat and veggies. Again, the weight started coming off; more slowly this time, but also more steadily. 190 came and went, then 185. Then I got laid off, and my weight stabilized at 185. More free time meant more time to prepare good food, but it also means more time to eat. Took me a little while to find the right balance. I got the food figured out, and the weight started to come off again, still slowly and manageably. Unlike in 2007, I this time I noticed my energy level increasing, as well as the quality of my sleep, and my overall sense of strength and well-being. I don’t know exactly what I did differently this time. Possibly less sugar.

So here I am now. My weight is now stable around 175. I have had to replace most of my wardrobe; three bags of large clothes off to Goodwill, and a small stash of 36″-waist pants for the holidays. I have a new job, and I walk or bike one and a half miles to work every day, carrying an 18 pound backpack. The fresh vegetables are becoming scarce, so I will have to start buying supermarket produce again for the first time in six months. I still indulge in the occasional snack food or pizza, but usually only on the weekends, and always in smaller quantities than before.

So: What do I think of the Primal Blueprint? Here is a list.

1. The food side of the PB was surprisingly easy to stick to, up to about 80%. Cutting out starchy root vegetables, legumes, and grains seriously impacts dining out. So I prefer to show moderation, even in moderation. Having said that, knowing that I got such great results even while not being super-strict gives me more respect for the PB.

2. The exercise/lifestyle aspect of PB – move slowly a lot, sprint occasionally, lift heavy things, get lots of sleep – fits in well with the current phase of my life. Martial arts and the PB complement each other nicely. The most difficult part is “get lots of sleep”.

3. The online community is great! Lots of support from the commenters and posters in the forums. Given the lifestyles of many of the PB aficionados, it feels like a distributed tribe.

4. The information on the site is well documented. Sisson is very good at backing up everything he says with references for people who want to do more research on their own.

So I feel comfortable advocating the Primal Blueprint. It worked for me. A few of my friends have tried it out, and have had great results. I haven’t felt this healthy since I was in my late 20s. If any of my half-dozen or so readers have tried this, post a comment! I am interested in hearing your story.

Posted in LifeTagged food, health comment on Exploring the Primal Blueprint

Procedural Generation, Intro

2011-10-31 John Winkelman

This is the first of what I hope to be many posts exploring the topic of procedural generation, particularly as it applies to game development and art.

At it simplest level, procedural generation (pg) is the use of a small amount of code, or an algorithm, to create a result, rather than creating that result by hand. Randomness and pseudo-randomness generally figure into the process, as well as set theory, emergence, and a wide variety of mathematical concepts such as fractals, the Fibonacci sequence, cellular automata, Perlin noise algorithms, and occasionally cryptography.

PG starts with the creation of a series of bits or numbers, then branches out into the myriad uses to which that series can be applied. How the numbers are chosen is just as important. So PG starts a level lower, at the algorithm which creates the data.

A list of numbers can mean almost anything depending on its context. But for a given context, not all sets of numbers will work. Therefore it is important to have a number generator which will produce useful data for a given task. This is where experimentation comes in to play.

But enough of the high-level stuff.

I have several years of notes, graphics, experiments, and source code through which I am currently sorting. Over the upcoming months I will post breakdowns of some of them, particularly those which can be applied to game development. And in those, I will be providing ideas about how to make PG useful, and how to tweak things so that using this method actually saves time and effort. Here are some of the ideas which I will cover:

  • terrain generation
  • town placement
  • resource placement
  • maze generation
  • cave/dungeon generation and population
  • place name generation
  • graphics creation
  • plant/tree generation

…and various combinations of the above.

In the meantime, click here to see the nearly 30 old entries I have made in this blog regarding procedural generation.

Posted in ProgrammingTagged procedural art comment on Procedural Generation, Intro

Hardy Dam Rustic Nature Trail

2011-10-30 John Winkelman

Hardy Dam Rustic Nature Trail sign

Back in mid-August my girlfriend and I spent an afternoon in Newaygo, walking along the Muskegon river just downstream from the Hardy Dam. The local Boy Scouts worked with Consumer’s Power to mark out an interpretive path called the Hardy Dam Rustic Nature Trail.

Stream from the woods

The trail is short – not quite three miles, round-trip – and is reasonably well marked. When we went the ground was wet from several inches of rain over the previous couple of weeks, so we got a little muddy. Still – a beautiful walk in the woods.

Red-backed Salamander (Plethodon cinereus)

One of the highlights was the discovery of at least a dozen red-backed salamanders. There seemed to be at least one under ever fallen limb. Since they are an indicator species, I take that to mean that the ecology of the Muskegon River is quite healthy.

Click on any of the photos to see the rest of the set on Flickr, or click here to start at the beginning.

Posted in Photography comment on Hardy Dam Rustic Nature Trail

Wikipedia as a Life Line for the Creative Urge

2011-10-28 John Winkelman

If you are like me – and I know I am – then you know that when the creative urge strikes, it doesn’t always come hand-in-hand with ideas. You know you want to do…SOMETHING… but have no idea what that thing is. Much like the adrenaline high of a sudden scare which leads nowhere, the creative juices which were so powerful in the morning sit unused, and gradually sour into an afternoon of sitting fatassedly on the couch, watching television.

While browsing through Wikipedia the other day in the grip of post-urge ennui, I realized that the “On this day…” link on the right side of Wikipedia’s main page is a treasure trove of disparate events, united by the theme of having happened on this particular date, offset by a certain number of years. What if someone was to take a random-ish handful of the events which happened on a day, and from them construct a story, or a poem, or the plot to an adventure game? I tend to look at things through the lens of a semi-practicing Buddhist, so the idea of cycles and recurrence appeals to me, and the filter of requiring a specific date makes the data set manageable – it provides the constraint which helps stave off the onset of option paralysis.

Putting this idea into practice, look at the page for September 25. A lot happened on this date in history. Here is a (very) small sample:

275-Tacitus becomes Emperor of Rome.
1513-Balboa reaches the Pacific Ocean.
1775-Ethan Allen surrenders to the British.
1789-Creation of the Bill of Rights.
1972-Norway rejects membership of the European Union.
2008-China launches the spacecraft Shenzhou 7.

Fletcher Christian was born in 1764, Lu Xun in 1881, and Catherine Zeta-Jones in 1969.

Johannes Secundus died in 1536, Pope Clement VII in 1534, and George Plimpton in 2003.

Coincidence? I THINK NOT!!!

But you can see where I am going with this. Narrative frameworks could be constructed which follow specific threads or sub-filters of the information on that page – say, only the events which are political in nature, or only the deaths of artists, or only the births which happened in years evenly divisible by 10. Start with a set of disjointed data. Apply an arbitrary filter. Come up with a loose narrative which allows for a significant number of the events in the filtered set. Apply a second filter. Tighten the narrative. A third filter. Now the narrative either falls apart, or contains within it the seeds of a story.

While it can be difficult to pull a complete story out of such an exercise, it can provide the seed of something much more complex. Or, perhaps there is a poem somewhere in the mix. Or the framing story of a game. Or even a film script.

At its simplest, constructing a coherent story from such an arbitrary list of data is a good thought experiment. With National Novel Writing Month starting in a few days this could be the seed of something amazing.

Posted in Writing comment on Wikipedia as a Life Line for the Creative Urge

Some Leaves

2011-10-17 John Winkelman

Clicking any of the photos will take you to the Lightbox set on Flickr.

Aspen Leaf

Oak Leaf

Maple Leaf

Wild Grape Leaf

Mulberry Leaf

Posted in Photography comment on Some Leaves

Blandford Nature Center, 9 October, 2011

2011-10-16 John Winkelman

Ducks and Turtles at Blandford Nature Center

October 9 was a great day for a walk around Blandford Nature Center. Warm air, lots of sunshine, light breeze, and all the animals were out soaking up some mid-autumn sunlight. Click the photo to see the rest of the set on Flickr.

Posted in PhotographyTagged Blandford Nature Center comment on Blandford Nature Center, 9 October, 2011

Circular HTML Elements Using CSS3 Border Radius

2011-10-13 John Winkelman

If you are using a “modern” browser, you should see a box full of circles.

 

abcde fghij klmno pqrst uvwxy z

If not, you need to upgrade your browser.

The circles were created using the new CSS3 border-radius property. The markup I used looks something like this:

<div id="post-20111013-a">
<span>a</span><span>b</span><span>c</span><span>d</span><span>e</span>
<span>f</span><span>g</span><span>h</span><span>i</span><span>j</span>
<span>k</span><span>l</span><span>m</span><span>n</span><span>o</span>
<span>p</span><span>q</span><span>r</span><span>s</span><span>t</span>
<span>u</span><span>v</span><span>w</span><span>x</span><span>y</span>
<span class="s2">z</span>
</div>
#post-20111013-a {width:640px;height:480px;outline:1px solid #999;background:#ffffff;}
#post-20111013-a span {
	float:left;
	width:50px;
	height:50px;
	margin:14px;
	border:1px solid red;
	background:#999999;
	-webkit-border-radius: 27px;
	-moz-border-radius: 27px;
	border-radius: 27px;
	text-align:center;
	line-height:50px;
}
#post-20111013-a span.s2 {
	float:none;
	clear:both;
	display:block;
	margin:20px auto;
	width:100px;
	height:100px;
	line-height:100px;
	-webkit-border-radius: 54px;
	-moz-border-radius: 54px;
	border-radius: 54px;
}
#post-20111013-a span:hover {
	-webkit-box-shadow: 5px 5px 5px 0px rgba(0, 0, 0, .5);
	-moz-box-shadow: 5px 5px 5px 0px rgba(0, 0, 0, .5);
	box-shadow: 5px 5px 5px 0px rgba(0, 0, 0, .5);
}
#post-20111013-a span.s2:hover {
-webkit-box-shadow: 0px 0px 20px 20px rgba(255, 0, 0, .5);
	-moz-box-shadow: 0px 0px 20px 20px rgba(255, 0, 0, .5);
	box-shadow: 0px 0px 20px 20px rgba(255, 0, 0, .5);
}

The first block is the HTML which makes up the above demo, and the second is the style sheet. Pretty self-explanatory. I set the border radius to slightly more than half of the diameter of the circle (width/height of the element). Putting the border radius at exactly half of the diameter renders as a very slightly squarish circle. You can play around with border-radius on this page at the w3schools. You can read more about the browser compatibility and best practices at The Art of the Web.

Unfortunately the hit area for each element is still a rectangle large enough to contain the circle, so in that sense it is not much of an improvement over using a background image. Still, it is a huge step in the right direction.

Posted in Programming comment on Circular HTML Elements Using CSS3 Border Radius

Mersenne Twister in Actionscript

2011-10-12 John Winkelman

A few years ago I attempted to create a game for the GameDev.net Four Elements Contest. I had an idea that I wanted the game to be a cross between Nethack and Elite – and maybe a little Spore – which is to say, loads and loads of procedurally generated content. I never got past a very rough prototype of the world-building engine, but I learned a lot about procedural generation, and game development in general. Specifically, that it takes a lot more time than I generally have available.

One of the artifacts of this experiment was an extremely useful Mersenne Twister class, which I ported over from a C class I found on Wikipedia. A Mersenne Twister is a seeded pseudo-random number generator. In other words, for a given input n and a range r, it will return a random number between 0 (or whichever number you designate as the lower bound) and r, using n as the seed.

How is that useful? If you want to be able to, for instance, save a game which is based on random number-seeded procedural content, you want to be able to return the same seed every time. And if someone wants to start a new game, you want that seed to be different, but also repeatable. If you can’t reload a saved game and have it be based off the same random number as before, then loading a game would be no different from starting a new one.

Anyway. Here is the Actionscript 3 class:

/*
   A C-program for MT19937, with initialization improved 2002/1/26.
   Coded by Takuji Nishimura and Makoto Matsumoto.

   Before using, initialize the state by using init_genrand(seed)
   or init_by_array(init_key, key_length).

   Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
   All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:

     1. Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.

     2. Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.

     3. The names of its contributors may not be used to endorse or promote
        products derived from this software without specific prior written
        permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


   Any feedback is very welcome.
   http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
   email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)

     -------------------

     Converted to Actionscript 2005 by John Winkelman
     Feedback welcome at john.winkelman@gmail.com
*/


/* Period parameters */
package org.eccesignum.utilities {
    public class MersenneTwister {
        private var N:Number = 624;
        private var M:Number = 397;
        private var MATRIX_A:Number = 0x9908b0df;   /* constant vector a */
        private var UPPER_MASK:Number = 0x80000000; /* most significant w-r bits */
        private var LOWER_MASK:Number = 0x7fffffff; /* least significant r bits */

        private var mt:Array; /* the array for the state vector  */
        private var mti:Number;

        private var seed:Number;
        private var returnLength:Number;
        private var maxSize:Number;

        private var returnArray:Array;


        public function MersenneTwister():void {

        }

        public function twist($seed:Number,$returnLength:int,$maxSize:int):Array {    //    seed number, number of values to return ,max size of returned number
            seed = $seed;
            returnLength = $returnLength;
            maxSize = $maxSize;
            mt = [];

            returnArray = [];

            mti = N+1; /* mti==N+1 means mt[N] is not initialized */
            var i:int;
            //var initArray=(0x123, 0x234, 0x345, 0x456);    //2010.04.20    modiied to the below
            var initArray:Array = [0x123, 0x234, 0x345, 0x456];
            init_by_array(initArray,initArray.length);
            for (i=0; i<returnLength; i++) {
                returnArray[i] = genrand_int32()%maxSize;
            }
            //returnArray.sort(16);
            //trace(returnArray);
            /*
            trace("\n1000 outputs of genrand_real2()\n");
            for (i=0; i<returnLength; i++) {
              trace(" " + genrand_real2());
              if (i%5==4) trace("\n");
            }
            */
            return returnArray;

        }


        /* initializes mt[N] with a seed */
        private function init_genrand($seed:Number):void {
            mt[0]= $seed & 0xffffffff;
            for (mti=1; mti<N; mti++) {
                mt[mti] = (1812433253 * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
                mt[mti] &= 0xffffffff;
                /* for >32 bit machines */
            }
        }

        /* initialize by an array with array-length */
        /* init_key is the array for initializing keys */
        /* key_length is its length */
        /* slight change for C++, 2004/2/26 */
        //    void init_by_array(unsigned long init_key[], int key_length)

        private function init_by_array($seedArray:Array,$seedArrayLength:Number):void {
            var i:Number = 1;
            var j:Number = 0;
            init_genrand(seed);
            //init_genrand(19650218);
            var k:Number = (N>$seedArrayLength) ? N : $seedArrayLength;
            for (k; k>0; k--) {
                mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525)) + $seedArray[j] + j; /* non linear */
                mt[i] &= 0xffffffff; /* for WORDSIZE > 32 machines */
                i++;
                j++;
                if (i >= N) {
                    mt[0] = mt[N-1];
                    i=1;
                }
                if (j >= $seedArrayLength) j=0;
            }
            for (k = N-1; k; k--) {
                mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941)) - i; /* non linear */
                mt[i] &= 0xffffffff; /* for WORDSIZE > 32 machines */
                i++;
                if (i>=N) {
                    mt[0] = mt[N-1];
                    i=1;
                }
            }

            mt[0] = 0x80000000; /* MSB is 1; assuring non-zero initial array */
        }

        /* generates a random number on [0,0xffffffff]-interval */
        private function genrand_int32():Number    {
            var y:Number;
            var mag01:Array=[0x0, MATRIX_A];
            /* mag01[x] = x * MATRIX_A  for x=0,1 */

            if (mti >= N) { /* generate N words at one time */
                var kk:Number;

                if (mti == N+1)   /* if init_genrand() has not been called, */
                    init_genrand(5489); /* a default initial seed is used */

                for (kk=0;kk<N-M;kk++) {
                    y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
                    mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1];
                }
                for (;kk<N-1;kk++) {
                    y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
                    mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1];
                }
                y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
                mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1];

                mti = 0;
            }

            y = mt[mti++];

            /* Tempering */
            y ^= (y >> 11);
            y ^= (y << 7) & 0x9d2c5680;
            y ^= (y << 15) & 0xefc60000;
            y ^= (y >> 18);

            return y;
        }

        /* generates a random number on [0,0x7fffffff]-interval */
        private function genrand_int31():Number    {
            return (genrand_int32()>>1);
        }

        /* generates a random number on [0,1]-real-interval */
        private function genrand_real1():Number    {
            return genrand_int32()*(1.0/4294967295.0);
            /* divided by 2^32-1 */
        }

        /* generates a random number on [0,1)-real-interval */
        private function genrand_real2():Number {
            return genrand_int32()*(1.0/4294967296.0);
            /* divided by 2^32 */
        }

        /* generates a random number on (0,1)-real-interval */
        private function genrand_real3():Number    {
            return ((genrand_int32()) + 0.5)*(1.0/4294967296.0);
            /* divided by 2^32 */
        }

        /* generates a random number on [0,1) with 53-bit resolution*/
        private function genrand_res53():Number    {
            var a:Number = genrand_int32()>>5;
            var b:Number = genrand_int32()>>6;
            return(a*67108864.0+b)*(1.0/9007199254740992.0);
        }
        /* These real versions are due to Isaku Wada, 2002/01/09 added */
    }
}

And it is called like this:

var twister:MersenneTwister = new MersenneTwister();
twister.twist(17436,100,50000); // seed number, number of values to return, maximum size of a given value

Since I wrote this, many other people have made versions in Actionscript. There is a comprehensive list on the Mersenne Twister page at Wikipedia.

Posted in ProgrammingTagged Flash, game development, procedural art comment on Mersenne Twister in Actionscript

Hiking in the Saugatuck Harbor Natural Area

2011-10-10 John Winkelman

Marsh in the Saugatuck Harbor Natural Area

Over the Labor Day weekend Cynthia and I spent a day hiking in the Saugatuck Harbor Natural Area. If you haven’t been, or haven’t heard of it, I can’t recommend it highly enough! It starts at the north edge of Oval Beach in Saugatuck, and extends north along Lake Michigan to the Kalamazoo River channel. There are several marked trails in among the dunes. You can see it on a map here.

Click the photo to see the rest of the set on Flickr.

Posted in Photography comment on Hiking in the Saugatuck Harbor Natural Area

Posts navigation

Older posts
Newer posts

Personal website of
John Winkelman

John Winkelman in closeup

Archives

Categories

Posts By Month

August 2025
S M T W T F S
 12
3456789
10111213141516
17181920212223
24252627282930
31  
« Jul    

Links of Note

Reading, Writing
Tor.com
Locus Online
The Believer
File 770
IWSG

Watching, Listening
Writing Excuses Podcast
Our Opinions Are Correct
The Naropa Poetics Audio Archive

News, Politics, Economics
Naked Capitalism
Crooked Timber

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

© 2025 Ecce Signum

Proudly powered by WordPress | Theme: x-blog by wpthemespace.com