Author Topic: "Random" Number Generation  (Read 10471 times)

Indigocell

  • Undead Slayer
  • ***
  • Posts: 190
"Random" Number Generation
« 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.

APorg

  • Dark Power
  • ******
  • Posts: 5336
  • Fanatic Xenophile
Re: "Random" Number Generation
« Reply #1 on: February 12, 2014, 05:43:54 PM »
The difference you are referring to is the difference between pseudorandom 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.
“Moral wounds have this peculiarity - they may be hidden, but they never close; always painful, always ready to bleed when touched, they remain fresh and open in the heart.”
― Alexandre Dumas, The Count of Monte Cristo

Norture

  • Still noobin' it up.
  • Dark Power
  • ******
  • Posts: 3516
  • ???
Re: "Random" Number Generation
« Reply #2 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.

Indigocell

  • Undead Slayer
  • ***
  • Posts: 190
Re: "Random" Number Generation
« Reply #3 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?

APorg

  • Dark Power
  • ******
  • Posts: 5336
  • Fanatic Xenophile
Re: "Random" Number Generation
« Reply #4 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.
“Moral wounds have this peculiarity - they may be hidden, but they never close; always painful, always ready to bleed when touched, they remain fresh and open in the heart.”
― Alexandre Dumas, The Count of Monte Cristo

swbf2lord

  • Guest
Re: "Random" Number Generation
« Reply #5 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.

Indigocell

  • Undead Slayer
  • ***
  • Posts: 190
Re: "Random" Number Generation
« Reply #6 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.

APorg

  • Dark Power
  • ******
  • Posts: 5336
  • Fanatic Xenophile
Re: "Random" Number Generation
« Reply #7 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."
“Moral wounds have this peculiarity - they may be hidden, but they never close; always painful, always ready to bleed when touched, they remain fresh and open in the heart.”
― Alexandre Dumas, The Count of Monte Cristo

APorg

  • Dark Power
  • ******
  • Posts: 5336
  • Fanatic Xenophile
Re: "Random" Number Generation
« Reply #8 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.
“Moral wounds have this peculiarity - they may be hidden, but they never close; always painful, always ready to bleed when touched, they remain fresh and open in the heart.”
― Alexandre Dumas, The Count of Monte Cristo

swbf2lord

  • Guest
Re: "Random" Number Generation
« Reply #9 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.

ManticoreRO

  • Dark Lord
  • *****
  • Posts: 810
  • Real Barovian
Re: "Random" Number Generation
« Reply #10 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).
Elena Vasilovici - "Better die for something than live for naught"

APorg

  • Dark Power
  • ******
  • Posts: 5336
  • Fanatic Xenophile
Re: "Random" Number Generation
« Reply #11 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.
“Moral wounds have this peculiarity - they may be hidden, but they never close; always painful, always ready to bleed when touched, they remain fresh and open in the heart.”
― Alexandre Dumas, The Count of Monte Cristo

ManticoreRO

  • Dark Lord
  • *****
  • Posts: 810
  • Real Barovian
Re: "Random" Number Generation
« Reply #12 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?
Elena Vasilovici - "Better die for something than live for naught"

APorg

  • Dark Power
  • ******
  • Posts: 5336
  • Fanatic Xenophile
Re: "Random" Number Generation
« Reply #13 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.
“Moral wounds have this peculiarity - they may be hidden, but they never close; always painful, always ready to bleed when touched, they remain fresh and open in the heart.”
― Alexandre Dumas, The Count of Monte Cristo

APorg

  • Dark Power
  • ******
  • Posts: 5336
  • Fanatic Xenophile
Re: "Random" Number Generation
« Reply #14 on: February 12, 2014, 07:29:56 PM »
An even better thread on the topic:

http://highergroundpoa.proboards.com/thread/11063
“Moral wounds have this peculiarity - they may be hidden, but they never close; always painful, always ready to bleed when touched, they remain fresh and open in the heart.”
― Alexandre Dumas, The Count of Monte Cristo

Meriana

  • Undead Slayer
  • ***
  • Posts: 169
Re: "Random" Number Generation
« Reply #15 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:)

Telkar

  • Dark Power
  • ******
  • Posts: 1693
Re: "Random" Number Generation
« Reply #16 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!

Bad_Bud

  • Developers
  • Dark Power
  • *
  • Posts: 4576
Re: "Random" Number Generation
« Reply #17 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.

ManticoreRO

  • Dark Lord
  • *****
  • Posts: 810
  • Real Barovian
Re: "Random" Number Generation
« Reply #18 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.
Elena Vasilovici - "Better die for something than live for naught"

Exordium

  • Developers
  • Dark Power
  • *
  • Posts: 1806
Re: "Random" Number Generation
« Reply #19 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.
« Last Edit: February 13, 2014, 03:50:34 AM by Exordium »

Soren / Zarathustra217

  • Lead director, main scripter, nutty geek, Community Council
  • Administrator
  • Dark Power
  • *
  • Posts: 12979
Re: "Random" Number Generation
« Reply #20 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.

Exordium

  • Developers
  • Dark Power
  • *
  • Posts: 1806
Re: "Random" Number Generation
« Reply #21 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
« Last Edit: February 13, 2014, 04:26:23 AM by Exordium »

Knas

  • Developers
  • Head DMs
  • Dark Power
  • ******
  • Posts: 8733
  • Worthless phony
Re: "Random" Number Generation
« Reply #22 on: February 13, 2014, 05:02:51 AM »

Aahz

  • Dark Power
  • ******
  • Posts: 1127
  • People don't like to be meddled with.
Re: "Random" Number Generation
« Reply #23 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.
"It never ceases to amaze me how bent out of shape adult people can get in a discussion on the best way to play make believe."

Ercvadasz

  • Dark Power
  • ******
  • Posts: 1109
Re: "Random" Number Generation
« Reply #24 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...)
Currently playing:
Rudrig von Rachenthall - the travelling merchant