Ravenloft: Prisoners of the Mist

Suggestions, Feedback & Bug Reports (OOC) => Module Feedback and Suggestions => Topic started by: Indigocell on February 12, 2014, 05:40:14 PM

Title: "Random" Number Generation
Post by: Indigocell on February 12, 2014, 05:40:14 PM
Quote
The number generator on the server doesn't accurately reflect die rolls anyways.

Quote
That's not true in my experience. It's a very common impression though and not limited to NWN.

I disagree with the second quote, as you might be able to tell by the quotes in the subject line...  

I have always been skeptical of NWN's so-called random number generation for the d20 system.  I was wondering if anyone knew exactly -how- the numbers are generated?  I have heard from developers on other servers before that the number generation is anything but random, it simply creates the illusion of it.

For instance, I was told that the number generation is determined by strange variables such as how long a character has been logged on, and where they happen to be standing on a particular map.

I've also been told that it is very difficult to simulate actual random numbers, and that is why such a strange sounding system is used in NWN.

This guy was a fairly well respected developer and I don't think he would lie, although it is possible I am not remembering exactly what he said.

In any case, I want to know if anyone has real insight into how the numbers are generated.  I also feel like rolls in the low end are far more common than they should be.  Does it really happen in PnP where you can roll 10 times and never get above a 4?  For some reason doubt that, but I am terrible at math.
Title: Re: "Random" Number Generation
Post by: APorg on February 12, 2014, 05:43:54 PM
The difference you are referring to is the difference between pseudorandom (http://en.wikipedia.org/wiki/Pseudorandomness) and random.

The difference between pseudorandomness and true randomness is only really relevant if you're worried that someone is hacking the client to predict or control dice rolls. Otherwise, without using exploits, pseudorandomness and true randomness are effectively the same to the human observer.
Title: Re: "Random" Number Generation
Post by: Norture on February 12, 2014, 05:55:29 PM
The rolls are ridiculously streaky. It's not just a perception thing, go and do crafting and you will have times when the majority of your rolls are under 5, and other times when the majority of them are above 15. Sometimes the game gets stuck doing streaky stuff. I'm not sure what resets it, it's possible the random seed is generated on character login? I'll try logging out for 15 minutes the next time I get stupidly bad streaky low rolls.
Title: Re: "Random" Number Generation
Post by: Indigocell on February 12, 2014, 05:58:01 PM
That's a little difficult to follow, doesn't make sense to me.

I would think that the pseudo-randomness of the number generation is a flaw in NWN, perhaps nothing can be done about it but it should be acknowledged.  

Could you explain a little better why pseudorandom is no different than truly random as far as we're concerned?
Title: Re: "Random" Number Generation
Post by: APorg on February 12, 2014, 06:01:19 PM
The rolls are ridiculously streaky. It's not just a perception thing, go and do crafting and you will have times when the majority of your rolls are under 5, and other times when the majority of them are above 15. Sometimes the game gets stuck doing streaky stuff. I'm not sure what resets it, it's possible the random seed is generated on character login? I'll try logging out for 15 minutes the next time I get stupidly bad streaky low rolls.

Sorry, it is a perception thing. Human beings are terrible judges of true randomness.
Title: Re: "Random" Number Generation
Post by: swbf2lord on February 12, 2014, 06:12:17 PM
The rolls are ridiculously streaky. It's not just a perception thing, go and do crafting and you will have times when the majority of your rolls are under 5, and other times when the majority of them are above 15. Sometimes the game gets stuck doing streaky stuff. I'm not sure what resets it, it's possible the random seed is generated on character login? I'll try logging out for 15 minutes the next time I get stupidly bad streaky low rolls.

Sorry, it is a perception thing. Human beings are terrible judges of true randomness.

I'll speak from experience and say no, it's not perception. It's not a true randomness.
Title: Re: "Random" Number Generation
Post by: Indigocell on February 12, 2014, 06:13:41 PM
As far as streaks are concerned, I do recall one very strange instance...

I forget how long it went on, but there was a time on my old server where my character would get max damage on his hit roll every time he hit.  17 Damage on every hit for quite awhile.  Bastard Sword (1d10) + 18 strength (+4), and favored enemy (+3).  I believe I was fighting goblins at the time, lol.

Maybe i was just extremely lucky, but that went on for at least 30 minutes.
Title: Re: "Random" Number Generation
Post by: APorg on February 12, 2014, 06:21:18 PM
I'll speak from experience and say no, it's not perception. It's not a true randomness.

Please give the mathematical analysis that supports this statement. I don't mean to be rude, but if you understood the mathematics or computer science behind this, you are basically stating that Bioware's programmers are completely incompetent. Your statement is as incredible to me, as it would be incredible for anyone who had received one of Norture's Valentine's cards to hear me say, "Norture can't draw."
Title: Re: "Random" Number Generation
Post by: APorg on February 12, 2014, 06:25:27 PM
I would think that the pseudo-randomness of the number generation is a flaw in NWN, perhaps nothing can be done about it but it should be acknowledged.

Using pseudo-randomness is not a "flaw" because it's good enough for any purpose the game was designed for. The difference between pseudorandom and true random is usually only important in things like cryptography.

Quote
Could you explain a little better why pseudorandom is no different than truly random as far as we're concerned?

Let me take the first sentence of the wikipedia article, because it explains the concept very succinctly.

"A pseudorandom process is a process that appears to be random but is not. Pseudorandom sequences typically exhibit statistical randomness while being generated by an entirely deterministic causal process." (Emphasis mine.)

Everything inside your computer is an "entirely deterministic causal process" -- that is to say, everything inside your computer has a certain state that is known and predictable. The time, the battery power, the way the memory is allocated, all this is known.

So in that sense, it is impossible to create something truly random from this because if you knew the exact state of the computer, any algorithm that produces a random number could be predicted, if you also knew the algorithm and could do the calculations fast enough.

Let's say I have an algorithm that takes the current time down to the millisecond, takes the temperature of the processor, and uses that information to calculate a pseudorandom dice roll. Quite clearly, if a hacker knows what the time on my computer is, and he can read the temperature of my processor from the BIOS monitor, and he knows what algorithm I'm using, then he can in theory predict what dice I am going to roll as I am rolling them (if he's fast enough).

True random number generators usually use some external source to introduce something purely unpredictable into the equation. Examples of external sources include: a microphone that picks up street noise, or the noise of the sea; the decay of atomic particles; that sort of thing.

It is much more difficult for the hacker to predict truly random numbers then because he then has to predict the noise of the sea.
Title: Re: "Random" Number Generation
Post by: swbf2lord on February 12, 2014, 06:26:45 PM
I'll speak from experience and say no, it's not perception. It's not a true randomness.

Please give the mathematical analysis that supports this statement. I don't mean to be rude, but if you understood the mathematics or computer science behind this, you are basically stating that Bioware's programmers are completely incompetent. Your statement is as incredible to me, as it would be incredible for anyone who had received one of Norture's Valentine's cards to hear me say, "Norture can't draw."

I don't feel like arguing the point with you, or discussing it really. I understand that you've got theories on it, but Bioware's programmers have been known to make mistakes before, this could have been one they overlooked.
The "streaks" described are quite real. And in no way does it imply they are incompetent, but it does in every way imply they are human. Humans, make mistakes.
Title: Re: "Random" Number Generation
Post by: ManticoreRO on February 12, 2014, 06:28:00 PM
I'll speak from experience and say no, it's not perception. It's not a true randomness.

Please give the mathematical analysis that supports this statement. I don't mean to be rude, but if you understood the mathematics or computer science behind this, you are basically stating that Bioware's programmers are completely incompetent. Your statement is as incredible to me, as it would be as incredible for anyone who had received one of Norture's Valentine's cards to hear me say, "Norture can't draw."

The randomness is not truly random but also it is percieved by us as such. Pseudorandomness is generated using an algorithm involving a seed from which a set of "random" numbers are generated. If you use the same seed for all players, all the numbers they roll will be the same. Now if you change the seed for each player, you will get different rolls. since NWN is programmed using the C++ language, I would assume the rolls use the internal C++ functions rand() and randomize(<here is the seed>). Unless the developers of nwn decided another algorhitm would be more suited for the dice rolls ( I did do such for a dice game I made for a school project, when I used the C++ random number generator and probabilities).
Title: Re: "Random" Number Generation
Post by: APorg on February 12, 2014, 06:37:51 PM
I don't feel like arguing the point with you, or discussing it really. I understand that you've got theories on it, but Bioware's programmers have been known to make mistakes before, this could have been one they overlooked.
The "streaks" described are quite real. And in no way does it imply they are incompetent, but it does in every way imply they are human. Humans, make mistakes.

The point is that streaks aren't anomalies -- they're normal statistical behaviour. Human perception tells us it's very odd to have these streaks, but human perception is biased and is going find them remarkable, all while ignoring the bulk of other unremarkable cases.

And every single computer game that involves randomness and has an internet forum community, also has its share of denizens that swears to heaven that these streaks are proof of the random number generator being borked. Go back to the early '90s Backgammon newsgroups and see what I'm talking about, if you want... Sorry, it's tinfoil hat territory unless and until you bring some hardcore mathematical analysis into play.
Title: Re: "Random" Number Generation
Post by: ManticoreRO on February 12, 2014, 06:40:12 PM
I'll speak from experience and say no, it's not perception. It's not a true randomness.

Please give the mathematical analysis that supports this statement. I don't mean to be rude, but if you understood the mathematics or computer science behind this, you are basically stating that Bioware's programmers are completely incompetent. Your statement is as incredible to me, as it would be incredible for anyone who had received one of Norture's Valentine's cards to hear me say, "Norture can't draw."

I don't feel like arguing the point with you, or discussing it really. I understand that you've got theories on it, but Bioware's programmers have been known to make mistakes before, this could have been one they overlooked.
The "streaks" described are quite real. And in no way does it imply they are incompetent, but it does in every way imply they are human. Humans, make mistakes.

Pretty sure in 10 years someone would have seen it, no?
Title: Re: "Random" Number Generation
Post by: APorg on February 12, 2014, 07:18:25 PM
Okay, here's an actually fairly good topic about this on an old forum.

http://www.avlis.org/viewtopic.php?f=4&t=34047&sid=22f33ad406e196c9cd1ecabd659999f5

A key post is the first post on page two, here:

http://www.avlis.org/viewtopic.php?f=4&t=34047&sid=22f33ad406e196c9cd1ecabd659999f5&start=25

Quote from: keikobad
Not going to link to it since it takes me so darn long to load up the bioware forums on my 56K, but if you search for it you'll find reams and reams of data collected by other people. The conclusiont was that the RNG was in fact random, and a developer added that it was basically as good or streaky as your Operating System's RNG, which is what NWN calls.

If they do indeed weight the die-rolls for some difficulty setting, the info would almost certainly be on the bio forums somewhere. I hope you folks didn't have to copy the numbers out of your in-game screen one-by-one!  :shock:

Unfortunately the original data on the Bioware forum may no longer be there, unless someone knows where it mgiht be archived.
Title: Re: "Random" Number Generation
Post by: APorg on February 12, 2014, 07:29:56 PM
An even better thread on the topic:

http://highergroundpoa.proboards.com/thread/11063
Title: Re: "Random" Number Generation
Post by: Meriana on February 12, 2014, 08:15:33 PM
Anyone concerned about streaks of similar rolls should do a hundred coin flips, note down the results and look for streaks there. Simplest random process there is. Streaks will crop up.

As aprogressivist pointed out, we are all awful at randomness. The human brain has evolved to look for patterns. It is why most everyone feel like the chance for a tail must surely be high after five heads. It hasn't changed - in simplistic models, it's still 50/50. (In reality, there's also the small possibility of the coin landing standing :lol:)
Title: Re: "Random" Number Generation
Post by: Telkar on February 12, 2014, 08:23:30 PM
Or note down 1000000 observations of d20 attack rolls / saving throws. Find their mean value. Should be around 10.5.

You can also check the number of rolls of 10 and below against the ones that are 11 and above, to see whether your conjecture of rolls in the low is right.

It'll need some serious journal logs scraping though.  :| But with that number of rolls you can be pretty certain!
Title: Re: "Random" Number Generation
Post by: Bad_Bud on February 12, 2014, 08:49:20 PM
Neverwinter Nights does seem to use time in some way as a seed value for generating pseudorandom numbers, and in some cases this can lead to strange results.

I was trying to create a function for a spell that would use pseudorandom numbers to give me a random quadrant from a unit circle (the range of possible values was 0 - 3).  I wanted to get each quadrant once, but I wanted to get them in a random order.  I was having trouble figuring out where I had screwed up my formula, so I was printing debug messages containing the numbers NWScript's Random() function had created on each attempt.

95% of the time it worked correctly.  By correctly I mean the numbers were seemingly random.  1 -> 1 -> 3 -> 0 -> 3 -> 3 -> 2

5% of the time something bad would happen, and the same value would roll 25 to 40 times in a row.  This is not normal behavior for a pseudorandom number generator.  While statistically possible, it was highly improbable considering I reproduced this behavior at least five times over the course of an hour of testing.

I agree people exaggerate the state of affairs for die rolls in this game, and I don't want people to start citing this post as "proof" while they failed a crafting attempt.  But the fact remains the pseudorandom number generator in this game is unreliable.  Luckily no one is able to craft or attack at 1000 times per second, and under most standard usage conditions the system generates reasonable numbers.
Title: Re: "Random" Number Generation
Post by: ManticoreRO on February 13, 2014, 01:48:19 AM
  For a random number generator to function properly, before any Random() function call another seed should be chosen. Example:

  while (anumber != 5)
{
  randomize(add seed here);
  anumber = random();
}

  if you use:

  randomize(add seed here);
  while(anumber != 5)
{
  anumber = random();
}
 
  the results will be less... random.

note: I do not know the syntax of the nwn random() function but you get the point.
Title: Re: "Random" Number Generation
Post by: Exordium on February 13, 2014, 03:08:56 AM
For a bit of technical explanaton on the terms:

In computer science, true random number generator is considered such which offers pseudorandom numbers from a large enough set of seemingly random data, so that the numbers generated can not be replicated in practice because the data, from which they were created, is too large and "random". For example, using large amounts of user input as the basis of random numbers is typically considered true random number generating.

In contrast, pseudo-random number generator is one which works on much smaller set of user data to produce seemingly random numbers. For example, an algorithm which is fed the current time in milliseconds and always produces the same number with the same time, is considered pseudo-random number generator. Probably the most commonly used random number generator, glibc's rand(), is an example of such algorithm.

Of course, neither of these are actually truly random. Computers are incapable of producing true randomness (except by the 0.000000000000000000000000000000000000000000001% chance of enough electrons quantum tunneling to just the right spot -- though even that might not be truly random) and by most part, so are humans.

It would technically be possible that the random number generator used by NWN is either a) too simple or b) deterministic (meaning, it returns same number with same seed) and being given same seed multiple times. I find it likely that it is glibc's rand(). While too simple for certain applications, it should be well good enough.

Now for the statistical stuff:

If you roll d20 400 times, it's likely that you roll any three numbers in row once while if you roll d20 8000 times in a row, it's likely you roll a streak of three 1s once.

Now the problem there is that human brain has the habit of making patterns out of anything. So when you require 10 bash attempts per chest and bust open 40 chests during a month, you're very likely to roll the same number three times in row. There's a 25% chance that those numbers are from 1 to 5 and 25% chance that they are from 15 to 20. Whichever it ends up as, we pick it up as either unusually lucky or unusually unlucky.

We also pick rolling, say, 1, 5, 3, 3, 4 as unusually unlucky. But rolling a number between 1 and 5 five times in row, is likely to happen when rolling 1000 times. Now, we tend to find those patterns from all rolls we make - not only chest bashing and crafting, but also saves, attack rolls, etc. And there are many of those in a week. It's a slippery slope, too: We may roll 1-5 three times in a row, then roll 11 and 8, then roll 1-5 another three times in row. If the 11 and 8 weren't enough to bash open the chest, in our brain the pattern of unlucky low rolls continues.

Regardless -- I suppose there is the off chance that the random number generator is either prone of generating the same number in specific seed ranges or its seed is supposed to be refreshed but isn't. Even so, in my own experience, there's no gross problem with it and any problems with it do not result in drastic alterations of game balance.
Title: Re: "Random" Number Generation
Post by: Soren / Zarathustra217 on February 13, 2014, 04:20:09 AM
We need to write a NWNx plugin that hooks up with a quantum computer - or a page like random.org that use atmospheric noise!

There is actually a flaw in NWNs random generator though, at certain times causing streaks of 0s (1s if rolling a dice). Our systems overcome this by always extending the random range, and re-generating on 0s.
Title: Re: "Random" Number Generation
Post by: Exordium on February 13, 2014, 04:24:43 AM
I just got 81 and 80 in row from random.org on my first attempt of rolling random numbers! The likelihood for that is one to ten thousand, so it has to be bugged!

But so there indeed is some flaw with the way NWN picks random numbers? Interesting - didn't know that. Good it is overcome tho. :P
Title: Re: "Random" Number Generation
Post by: Knas on February 13, 2014, 05:02:51 AM
(http://s1.hubimg.com/u/830988_f520.jpg)
Title: Re: "Random" Number Generation
Post by: Aahz on February 13, 2014, 09:28:50 AM
Heck one time years ago I was fighting 8 werewolves (back before the morale script and monsters would just swarm you until you killed them all). I died because they all hit and they all rolled criticals in the same round..... this was after 8 rounds of me rolling nothing above a 5. That was my most memorable WTF moment with NWN die rolls ever.
Title: Re: "Random" Number Generation
Post by: Ercvadasz on February 13, 2014, 04:48:11 PM
worse is how 50% of the time improved invisibility potions do not make anything.
(The effects that are tied to the potion do not work...I think i died more cuz of this bug than the roll 9 times twenty out of 10 rolls, which did happen to me...)
Title: Re: "Random" Number Generation
Post by: Knas on February 13, 2014, 06:59:37 PM
worse is how 50% of the time improved invisibility potions do not make anything.
(The effects that are tied to the potion do not work...I think i died more cuz of this bug than the roll 9 times twenty out of 10 rolls, which did happen to me...)


 :awesomeface:  Suuure
Title: Re: "Random" Number Generation
Post by: Bad_Bud on February 13, 2014, 07:02:13 PM
worse is how 50% of the time improved invisibility potions do not make anything.
(The effects that are tied to the potion do not work...I think i died more cuz of this bug than the roll 9 times twenty out of 10 rolls, which did happen to me...)


 :awesomeface:  Suuure

Nah, it's true.  It's not random though.  You have to stand still after consuming a potion of Improved Invisibility.  If you move or take an action immediately after consuming one, the invisibility never applies.
Title: Re: "Random" Number Generation
Post by: Anonymoose on February 13, 2014, 07:27:46 PM
worse is how 50% of the time improved invisibility potions do not make anything.
(The effects that are tied to the potion do not work...I think i died more cuz of this bug than the roll 9 times twenty out of 10 rolls, which did happen to me...)


 :awesomeface:  Suuure

Nah, it's true.  It's not random though.  You have to stand still after consuming a potion of Improved Invisibility.  If you move or take an action immediately after consuming one, the invisibility never applies.

"Hey Teemo, please stand still so I can use my Noxian Guillotine" - Darius

Nah but seriously, I've noticed this TERRIBLÉ bug
Title: Re: "Random" Number Generation
Post by: Ercvadasz on February 14, 2014, 12:04:33 AM
worse is how 50% of the time improved invisibility potions do not make anything.
(The effects that are tied to the potion do not work...I think i died more cuz of this bug than the roll 9 times twenty out of 10 rolls, which did happen to me...)


 :awesomeface:  Suuure

Nah, it's true.  It's not random though.  You have to stand still after consuming a potion of Improved Invisibility.  If you move or take an action immediately after consuming one, the invisibility never applies.

"Hey Teemo, please stand still so I can use my Noxian Guillotine" - Darius

Nah but seriously, I've noticed this TERRIBLÉ bug

Or if you are being hit.
Sometimes that does not make the potion work neither.
Title: Re: "Random" Number Generation
Post by: Ercvadasz on June 30, 2015, 12:14:43 AM
worse is how 50% of the time improved invisibility potions do not make anything.
(The effects that are tied to the potion do not work...I think i died more cuz of this bug than the roll 9 times twenty out of 10 rolls, which did happen to me...)


 :awesomeface:  Suuure

Nah, it's true.  It's not random though.  You have to stand still after consuming a potion of Improved Invisibility.  If you move or take an action immediately after consuming one, the invisibility never applies.

"Hey Teemo, please stand still so I can use my Noxian Guillotine" - Darius

Nah but seriously, I've noticed this TERRIBLÉ bug

Or if you are being hit.
Sometimes that does not make the potion work neither.

Died of it again...[sigh]
Title: Re: "Random" Number Generation
Post by: McNastea on June 30, 2015, 12:58:34 AM
I'd have to agree with approgressivist on this one. Humans look for meaning and patterns in things and create them even when they aren't there, so when you're crafting and get a string of numbers that are all near to each other or even the same you figure that there must be something wrong when in fact each roll has nothing at all to do with the one before or after or three rolls before or three rolls after and so on. Each is a new roll and is an entirely separate event from any of the others. Statistically, if you rolled d20 and got say a 16, the odds of rolling another 16 are in no way increased or diminished because of that first roll. They are the same, always. There is no pattern-you create the illusion because that's what your brain is programmed to do, find meaning in things.
Title: Re: "Random" Number Generation
Post by: Merry Munchkin on June 30, 2015, 01:17:30 AM
Also, we tend to not pay as much attention to successful rolls than unsuccessful rolls.  Most of the time in combat or crafting, we enjoy the "hits" without reflecting on the number, and freak out over the "misses" and pay close attention to those numbers.  Thus, we tend to notice the bad streaks more than the good streaks.
Title: Re: "Random" Number Generation
Post by: Jeebs on June 30, 2015, 02:50:37 AM
I remember rolling a character for a PnP game some years ago, where my DM was laughing and saying you're generally lucky to roll even a 14... all my ability rolls were 16s, except for one 14 and an 18... so yes, streaks can and do happen even with true randomness. The look on his face though....  :lol:
Title: Re: "Random" Number Generation
Post by: Thoraion on July 12, 2015, 03:53:52 PM
From my experience i can confirm the "clustered" random Numbers. Time definitely plays a role there. Bad in fights, exploitable in crafting just by Waiting a few Minutes When Results focus in the lower Range of possible Results.
Prohibited? Don't be ridiculous.
Title: Re: "Random" Number Generation
Post by: de_reguer on July 13, 2015, 12:43:32 AM
From my experience i can confirm the "clustered" random Numbers. Time definitely plays a role there. Bad in fights, exploitable in crafting just by Waiting a few Minutes When Results focus in the lower Range of possible Results.
Prohibited? Don't be ridiculous.

I don't really understand the specifics of it, but the string of clustered numbers definitely exists, and is a known "bug" of the NWN system. A DM who knew something about coding explained to me a long time ago on another server. it has something to do with each cell having a preset number sequence embedded in it as you enter it. So NWNs random number generator isn't random at all. It follows a genuine formula that just has the appearance of randomness, and I think each number generated is somehow tied to the one immediately before it. That's where the weird strings of clusters can come from. The upside is it can also work in the players favor. I have seen numerous times over the years strings of 4 and 5 crits with a weapon that has a 10% or 20% chance to score one.
Title: Re: "Random" Number Generation
Post by: DrXavierTColtrane on July 13, 2015, 04:44:48 AM
I don't know whether the NWN random number generator is flawed as you describe, but getting 5 criticals in a row with a 10 percent chance is not dispositive that it's wonky if you've seen it "over the years." The chance of getting a second critical right after a first is 10 percent. A third is then 1 percent and so on. So five in a row should happen once every 10,000 criticals. That's low, but how many critical hits have you had "over the years"? If you've had 60,000 initial criticals, than you would have *expected* (mathematically) to have followed 6 of those with 4 more consecutive criticals--even though your chance each time was low.

I kind of wonder about NWN myself, but pseudorandomness that approaches actual randomness is so easy to program I would have to presume it intentional if a decent game programmer had made a game that the randomness was so bad end users could prove it.
Title: Re: "Random" Number Generation
Post by: Merry Munchkin on July 13, 2015, 08:38:41 PM
I don't really understand the specifics of it, but the string of clustered numbers definitely exists, and is a known "bug" of the NWN system. A DM who knew something about coding explained to me a long time ago on another server. it has something to do with each cell having a preset number sequence embedded in it as you enter it. So NWNs random number generator isn't random at all. It follows a genuine formula that just has the appearance of randomness, and I think each number generated is somehow tied to the one immediately before it. That's where the weird strings of clusters can come from. The upside is it can also work in the players favor. I have seen numerous times over the years strings of 4 and 5 crits with a weapon that has a 10% or 20% chance to score one.

Interesting.  If this is highlighted quote is accurate (and I don't know how NWN is programmed), then the game engine uses something similar to what is called the "middle-squares" method of generating a key number.  By way of background, a mathematical "random" number generator, as people have noted, does not actually generate "random" numbers.  Think of it as the equivalent of a cypher machine (for making and breaking secret codes, like ENIGMA or PURPLE in WWII).  It uses a numeric seed value as its starting "key", and from this key it uses a mathematical algorithm to generate a sequence of numbers that appear to be random, but in fact follow a predictable mathematical pattern if you know the key.  Any sequence that is generated from the same key value will be identical.  Thus, if you know the key value, you can predict the pattern if you have the algorithm.  This is how code breakers break down enemy cyphers.


This type of "random" number generator in a computer game like NWN has its algorithm fixed, but the key (seed value) can be changed, resulting in different strings of numbers.  Thus, the critical element in making a string of numbers appear to be as random is being able to generate a wide variety of starting seed values/keys. 

John Von Neumann developed a simple way to quickly generate random-ish numbers for creating keys (at least simple for a computer) called the "middle squares" method -- to generate a sequence of 4-digit numbers (for example), you start with a 4-digit number which is then squared, producing an 8-digit number. The middle 4 digits of the result would be the next number in the sequence. This process is then repeated, squaring this new 4-digit number to generate a new number and so on.  Thus, each value is predicated on the values before it.  This process creates the "random" 4-digit seed value for the computer to plug into its algorithm.  For simple game purposes, this process would generate a sufficiently large number of keys that people would not necessarily notice if the same key was used later on.

It is not the most sophisticated way to create a cypher, but it works for something as simple as a game like NWN.  However, these types of generators do produce odd quirks if the length of the numbers used is too short, or has zeros at the beginning of the number, or other wonky things.  The trick is to develop a way to generate these random-ish numbers quickly, so that the computer doesn't slow down to a crawl -- the more sophisticated the method used, the more computing power it takes.

This doesn't explain why you see repeats in sequences in any given series, but it is an interesting insight into the game engine.  At least I thought it was interesting.  But then again, I am weird about puzzles and numbers.

Title: Re: "Random" Number Generation
Post by: Syied on July 29, 2015, 02:34:47 AM
What McNastea said. When you get a run of bad rolls and wait it out before resuming your rolling, and then feel better about your new results, the reason you feel better is because that recess allowed your mind to defocus on the negativity and psychosis of the previous results, essentially forgetting their (ir)relevance.

Don't go chasing order in NWN's randomness; it's all in your head. But don't worry, because we all belong in a loony bin anyway  ;). Instead of trying to unravel why you occasionally get three 1s in a row, try having your character be bewildered at such results and develop insane superstitions about it IC!   :lol:
Title: Re: "Random" Number Generation
Post by: APorg on July 29, 2015, 04:54:37 AM
(http://resources.infosecinstitute.com/wp-content/uploads/121411_1611_SecureRando1.png)