Home » Top Secret » Pseudo Random Number and Creating Behavior.

Pseudo Random Number and Creating Behavior.

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 46 other followers

In computing, there’s something known as a pseudo random number generator.

This pseudo random number generator is used EVERYWHERE by computer programmers around the world for a wide array of activities on all computers to create the appearance of randomness in the programs they create.

But to be clear.

Pseudo, in non-technical terms can be translated to ‘kinda, but not really’.

So let’s say you’re playing a computer game.

In Solitaire, a pseudo random number will be generated by the programmer to define which cards occur in what order – with the boundaries of 1 to 52 – and all the cards in the deck will be lined up in a row by suit, from Ace, Two, and so on to King of Hearts, and then Spades, and so on. So let’s say the random number generated is 12, that will refer to the Queen of Hearts.

In a first person shooter game like Fear, an enemy might have one of seven different actions to perform based on a player’s presence, for instance, let’s say action 1 might be ‘duck and cover’, action 2 might be ‘open fire’, action 3 might be ‘run’, action 4 might be ‘go get a friend’, action 5 might be ‘trip the alarm’, action 6 might be ‘tip a vending machine to make cover’, and action 7 might be ‘rush the opponent’. So while playing the game, a random number would be generated – from 1 to 7 – let’s say the result is 2, and as a result the enemy might hold their position and simply open fire.

In a dialog based game such as Leisure Suit Larry, you might approach a woman who might have one of three primary responses at first when you go to talk to her. Response 1 might be ‘I am not interest at all’, response 2 might be ‘Some other time maybe’, and response three might be ‘Sure, let’s go find a place and have sex NOW’. So while playing the game, the programmer might have code which generates a random number from 1 to 3, and as you’re playing a ‘3’ is generated, and the woman is now more than happy to go have sex with the player.

And in a more dynamic environment such as a Massively Multiplayer Online Roleplaying game (MMORPG) such as Worlds of Warcraft, a non player character may be programmed to recognize (or NOT) that you’re of a specific class and level, and will approach you with one and only one of three quests that when completed, provides your character uniqueness because the other two quests are now inaccessible. So let’s say quest 1 provides a new skill which makes you absolutely undetectably invisible anytime you want without reagents, quest 2 results in the ability to teleport anywhere in the world you want to as long as you’re not in combat, and quest 3 results in the ability to dual class and the new class starts at level one with your current skills and stats intact (dual classing will clearly raise up in ranks fast and won’t require nearly as much time to level as the first class). However. This quest is completely random. So the programmer creates an algorithm which selects 1 to 3 and you wind up with 3 – the ability to dual class.

If you’re playing chess with a computer. There’s twenty possible moves to open with. And if this was done in a strictly random fashion, the programmer might select a number from 1 to 20 which then executes the move as an action associated with each number.

But two things to take into consideration when learning about seemingly random behavior within a computer system

  1. Programmed Rules

    Especially with chess – EVEN though the number of moves might be randomly based, there may be rules which literally limit the opening moves of a chess game to one of 14 moves. Put specifically, a rule could be put in place which says ‘dont expose the rook, queen, or king on the first move’, which limits the number of potential choices the computer can make by about half.

  2. Weight

    In combination with rules, certain moves might be more preferable to other moves – from the start. These moves are said to be ‘weighted’, and effect the ‘chance’ that it will be selected by randomly. For instance. Let’s say I am thinking of a number from 1 to 3, but I like the number 2 so the percentage chance that I’ll choose that is 50% and the percentage chance of selecting a 1 or 3 is 25% each. So rather than the pseudo random number generator selecting a number from 1 to 3, it now selects a number from 1 to 100 to respect the weights, where 1 to 25 is equal to a 1, 26 to 75 is equal to a 2, and 76 to 100 is equal to a 3. The random number generated is 72, which provides us the weighted random number of 2.

There’s different methods for ‘weighing’ and implementing rules. All helps random behavior seem somewhat more predictable masking the pseudo random generation methods used.

Pseudo random numbers are also used for ANY cryptography – whether you’re using Skype or buying something online in a secure connection from Amazon. pseudo random numbers are leveraged for encrypting communications to make it that much more difficult for someone ‘observing’ these communications to understand what you’re doing.

How to create a pseudo random number

All computer languages are binary based, so whether you’re programming in Java, Python, Visual Basic, .Net, C++, or whatever, all computer languages, and how to create a pseudo random number is very similar between all these languages.

There’s a formula used to create the random number which is always based on something called a seed – a number the programmer typically enters into the source code – and a time stamp. The two are usually combined with each other which helps the pseudo random number be a bit more unpredictable, increasing it’s variability.

Why does all this matter?

Let’s say you’re developing an artificially intelligent character in a game.

That character may come with a background and history which weighs every choice he/she/it makes.

For instance. Let’s say there’s a random encounter that can happen with this character which has a 99% chance of resulting in violence and a 1% chance of it not resulting in violence. Random chance is – it’s going to result in violence. However. If this character’s information is taken into account, and the chance of violence is then weighted – tremendously in the case where this character abhors violence – then this readjusts the percentage chance there will be violence dramatically. So much so if weighted, that what was once a 99% chance of violence is now only a 1% chance of violence or less.  Still an off chance. but weight can affect random results dramatically.

Now I see the same thing in real life.

Which is why I’ve concluded I’m in a simulation.

Every morning, for a year when I first arrived here in Los Angeles, I’d watch the same truck with a ginormous phallically based ad of a huge sausage roll by by on the freeway at precisely 10am +/- about 15 minutes, but on one day a week, randomly, I wouldn’t see the truck.

So Algorithmically, to define this day off – the day Monday would be equal to 1, through Friday which would be 5, so when a day was selected randomly, that day wouldn’t display the ‘phallic truck’ ad.

So let’s say the number 4 is selected. So this Thursday, that truck won’t be there.

Then, I have something else to consider. The truck didn’t arrive every day at precisely 10am, it arrived between 9:45am and 10:15.

30 minutes to consider. So for each day, I’d randomly selected a number from 1 to 30, and I’d repeat this four times. let’s say it’s 27 on the first day, it’s 3 on the second day, it’s 7 on the third day, and 19 on the final day. So on Monday, the truck would roll by at 9:45am + 27 minutes which is 10:12am, on Tuesday, the truck would roll by at 9:48am, on Wednesday it would roll by at 9:52am, we’d skip Thursday, and on Friday it would drive by at 10:04am.

There’s no weight consideration to take into account with this.

But here in Starbuck’s – I’ve noticed a similar thing.

AS a woman walks in – at the point on the walkway of the counter entering the store, a woman will predictably take her hand under her long hair and flip it outward. The percentage chance I place on this activity is about 60% occuring.

Where weight comes in is two factors – the younger or older they are the less the likelihood. So weight might slide the scale of percentage downwards dramatically to decrease the likelihood of the event. Making it seem a little more random.

And also, hair length matters, the shorter the hair, this diminishes the likelihood of the event happening dramatically as well.

So just now. A young blonde woman walked in who had long hair.

The probability of the event occuring would be 60%, no weights would be applied.

And sure enough. she does the flip, as expected at the point expected.

Right behind her, an equally younger girl walked in, with very short hair. Let’s say the weight adjusted for short hair might scale the likelihood of her doing it the flip from 60% to the short hair weight adjustment of 20% – making the final random value 0.2 * 0.6 = a 12 % chance she’ll do it. But guess what? She just did a flip with the little hair she actually had. So I might have to revise my number upwards for people with short  hair.

So here’s the interesting thing about pseudo random numbers.

When paying attention to the outputs.

It’s actually possible to figure out the methods used to generate the random number.

To replicate those methods.

And reverse engineer anything to create highly accurate models of just about anything imaginable. Understanding, of course, that three primary things create the seemingly unpredictable end result. The random number generation scheme itself, the rules which go into it, and the weight assigned to each.

Without ever having to touch the source.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Enter your email address to follow this blog and receive notifications of new posts by email.