random numbers and NS

Post your tips, ideas for improvements, requests for new features, etc. here
Locked
hatter
Noob
Posts: 23
Joined: Fri Oct 15, 2004 2:24 pm
Location: seattle

random numbers and NS

Post by hatter »

howdy,

I had an idea the other day that might speed things up a little bit on the server. One of the things that kills CPU time so often are single or double floating point calculations (fractions and decimals instead of simple integers for the rest of us). Anyhow, a game like this will involve plenty of random numbers in the dice throw. Random number generation can be a particularly effective CPU killer in this regard. So here's an idea....

Have an array of 1000 (or 10,000 or more) pre-generated random numbers in memory already. Then each time the server needs a new number it just indexs up by 1 entry and gets the number. In this case it's just simple integer computation and very fast. On a single player system this would be very poor and quickly become apparent to the user (ie things are not random). However, on a larger multiplayer server, the players themselves (by doing different actions all over the server, all the time) would make the list essentially random for any given player. Do you follow?

now, while this might seem like a simple thing to code, i realize it might be unfathomabley difficult to introduce into Bioware. Or it might just be down right impossible. But if there's a way to change it from calculating pure random numbers (well, they're still pseudo random, but who cares), to pulling a number out of a list each time, then it might make sense. In fact, if I had to guess, i'd say "impossible" with bioware. But I don't reallly know anything about it.

Anyhow, just a thought.

User avatar
Flailer
-2 Penalty in Daylight
Posts: 2503
Joined: Wed Oct 08, 2003 11:54 am
Location: Central Virginia

Post by Flailer »

I'm pretty sure for something used as often as random rolls are for this game, they got that function pretty close to the metal. Probably anything we could do in script would be much slower than the hardcoded functions.
Flailer
NS Developer

None of us is as dumb as all of us.

User avatar
DeputyDog
Addict
Posts: 1523
Joined: Mon Dec 16, 2002 6:49 pm
Location: Austin, TX
Contact:

Post by DeputyDog »

Nice idea though. Very true for a multiplayer game.
I wonder if they already do it that way.
DeputyDog
Founder
Neversummer
gmcever @ gmail.com

https://www.facebook.com/neversummer4

Image

Myrdyr
Newbie Helper
Posts: 266
Joined: Sun Dec 11, 2005 11:31 am

Post by Myrdyr »

I wish I could remember what NWN actually uses, but this discussion has come up on multiple servers that I've played on. If I remember correctly, Bioware is using the compilers built-in pseudorandom number generator, which is a very sad one at that. If it could be changed replaced (something that I also don't recall well, though I know many certainly try), the Mersenne Twister is an incredibly good generator that is so fast that pre-computing numbers instead would be a waste of time and memory. http://en.wikipedia.org/wiki/Mersenne_twister

User avatar
Flailer
-2 Penalty in Daylight
Posts: 2503
Joined: Wed Oct 08, 2003 11:54 am
Location: Central Virginia

Post by Flailer »

I like it just cause of the name...
Flailer
NS Developer

None of us is as dumb as all of us.

Umpa
Developer
Posts: 73
Joined: Mon Mar 27, 2006 2:58 am

Post by Umpa »

Does anyone know what NWN2 will be using for this function? If its still the same one, perhaps this should be brought up on thier boards. This function would be the basis for just about everything, mob movement, all checks and combat.

One of the things that might help if CPU was the issue, was tone down some of the ingame animal fighting, which is fun, but not totally needed. Random cpu movements give the game flavor though, so its just something to look at if you hit the wall.

What kind of server does NS run on now? Any specs? I actually do server architecture and have for the past 7 years, RISC, IA32, and IA64. My current server types handled 2000 people running applications on them. I might be able to help a bit there with recomendations if the specs were known.

Umpa

hatter
Noob
Posts: 23
Joined: Fri Oct 15, 2004 2:24 pm
Location: seattle

Post by hatter »

I actually use MT at work and it's a great way to get random numbers fast as possible. But it's still going to be slow compared to this (if the two schemes are coded at the same level). What I'm suggesting would be to only index a single array once (or only a few times) for each random number. MT performs a much larger number of integer shifts to arrive at the random number. Using the stock MT will further introduce a Floating point calculation when you convert the decimal to integer (you could get around this in a clever way, but it's still more integer computations).

Don't get me wrong, MT is a great routine when you need a huge, reliable series of (pseudo) random numbers quickly. However, there are (I believe) plenty of poor random number generators that will perform faster than MT. They just happen to show their true non-random nature very quickly (where as MT is sufficient for most applications by providing a very long series of random numbers).

hmmm.... anyhow. There's more to think on this.

Lokey
-2 Penalty in Daylight
Posts: 3094
Joined: Mon Dec 16, 2002 6:49 pm
Contact:

Post by Lokey »

NWN1 uses a standard random generator for some functions, just a big error in its seeding means it always returns the same sequences. Supposedly fixed for NWN2 at least a year ago (when the devs had more time and inclination to stop by irc they did dish a few things...try the NWN2 channel on NWNConnections irc server).
Tep wrote:I login and there's a dwarf to kill. You can't ask for much more than that.
Alkapwn wrote:NC has the most amazing melee build there is. Its a friggin unstopable juggernaut of pain.

havelot
Noob
Posts: 34
Joined: Wed Jun 14, 2006 2:27 pm

Post by havelot »

NWN1 uses a standard random generator for some functions, just a big error in its seeding means it always returns the same sequences.
Thank you for that piece of information. I have thought and said for years the random number generator in NWN is whacked. The results were just too improbable, like rolling the same number 6 or 7 times in a row when trying to maximize your HPs on a level-up. If such a thing occured once every two months, I could have no complaints. But it happens quite a bit, much to my dismay.
"Do unto others as you would have them do unto you."

Locked

Return to “NS4 Ideas and Suggestions”