View Single Post
Captain
Join Date: Jun 2012
Posts: 1,178
# 172
04-12-2013, 10:41 AM
Quote:
Originally Posted by royalsovereign View Post
Every game ends up having discussions like these...

A) I've tried X 1000 times and only gotten y result 3 times, it's borked!
B) Dude, your sample is too small. If you do it 100,000 times it'll be good.
A) and B) argue awhile with others chiming in how their anecdotes prove A) or B) is right/wrong/crazy.
C) *I've* done (insert OCD-level insane number of reps) and only gotten y __ times. A) is right, something is borked.


Well, let me toss something out onto the fire.

Lets say a given RNG needs a sample set of at least 100,000 to approach a truly random distribution. The problem is, to see that even distribution, every result of that RNG needs to be in the data set. Which is just fine if you're feeding it one operation and looking at the results of 100,000 consecutive iterations.

Unfortunately, in a game, that RNG is working on hundreds of different data sets at any given time.

I really don't see how you could ever collect enough data to expect truly random results. The game would have to be coded so that each specific function had its own dedicated RNG associated with it to approach any kind of even distribution.
I have no idea what you are trying to say. In most standard libraries, the pseudorandom number generator is not "fed an operation" and does not "work on a data set". Typically, you call an initialization function to pass the PRNG a seed. Then, you make multiple calls to another function to get pseudorandom values. Sometimes, this function will take a numeric range. Otherwise, the range will be full 32-bit or 64-bit range allowed by the system. How you interpret the value returned is up to you. Usually, the programmer will just mod the returned value by the number of categories. For example, suppose there are 10 categories. The programmer will use the integers 0 to 9 to represent them. If the PRNG returns 12332482, then just compute 12332482 mod 10 = 2 to select a category.

I should be able to use the same PRNG for multiple uses, even with the same seed. For example, suppose I have need to select one of 3 colors and one of 4 shapes. The code will look something like this:

seed(s);
color = rand() mod 3;
shape = rand() mod 4;

Unless the library you are using is poorly implemented, this method should produce roughly uniform distributions.

Last edited by frtoaster; 04-26-2013 at 09:38 AM.