Sunday, July 10

PGP - Part 2 "Pesudo Random Numbers Revisted"

A Revisit already?!

This is only the second part, of what I can already tell will likely be a large collection of posts, and we are already revisiting some of the content from the original post. At the end of part 1 you may have noticed that I remarked about a second possible PRNG we might use.

After thinking about it more I decided I wanted to implement multiple PRNGs from the start. This will give us the capability to see the difference in the output just by switching which PRNG we use. Also making these changes now will make it much easier for us to add additional PRNGs later without having to make excessive changes.

My Prng Global Javascript Object

  • function Prng ( seed, name )
    • function MWC (seed)
      • return function (max,min)
    • function INDIEGAMR (seed)
      • return function (max,min)
    • switch (name)
      • case "INDIEGAMR"
        • return INDIEGAMR(seed)
      • case "MWC"
      • default:
        • return MWC(seed)

function MWC - (Source Code)

function INDIEGAMR - (Source Code)

function Prng - (Full Source Code)

Introductory Foray into Procedural Generation

There was a lot of changes, and additional support code needed in order to make our lives easier later. Now we finally get to start experimenting with procedural generation. Starting very simply I have created a couple pens which test that my Javascript works.

The first test simply pseudo randomly generates 625 people who are determined to either be "Male" or "Female."

The second test adds an additional option. This could be Ogre, Dragon, or any other option you might wish to have.

The "brains" of these versions:

Changing the value in the call to prng() from 2 to 1 changes the options to two. The reason for this is that the function prng will always return a value between 0 and which ever value you call it from. Using the Math.round function allows us to convert the results to a integer value.

update: 2016.07.10

I realised after I had finished this post, and gone on to do other things, that the variable name "sex" did not exactly describe what I thinking it should. Like so many things, variable names, can be hard to get the perfect name the first time.

I have changed the variable name in the examples, and added a updated version of the current "brains" to this post.

The "brains" (updated version):

Continue with ...


Post a Comment