LorrMaster42 wrote:Made a bunch of adjustments to it. Now the system can store multiple models that share the same design together (so straight walls and corner walls of the same design can be grouped together). I am now working on the actual design of the dungeon and how the models will be placed.

One thing I'm struggling with is how to go about creating the seed. I've looked up a couple random number generators, but I can never understand the code for it or how to get a good output from a range of values. I'm also not sure what is the best way to use the seed once I've got it working.

Warning: This turns into a mini-rant on statistics at the end. Fortunately, you can stop reading after the paragraph after point 3) The next paragraph is a short intro to how to use cryptography, and after that, the mini-rant.

Ok, so pseudo-random number generators take a seed value, *modulus it by a prime number, and then run some more math to generate the next seed. Some prime numbers are better; for example, 7 is better than 5, because while 5 is prime, it'll also tend to have a shorter pattern; or what's called a "period". I could take a guess at why this is, but it'd only be a guess.

A bit more pRNG math. The reason it's pseudo-random is that, given a seed number and a pRNG formula, you will generate the exact same sequence each and every time, and the sequence will repeat. From start to finish is a "period". The smaller the prime number, and the less it fits certain traits prime numbers can have, the smaller the period. Again, I don't actually know what traits make a good prime number.

So, let's do a bit of math with 7. We'll take a number between [0, 20] for our seed value, modulus it by 7, multiply it by itself * 4, and then use that for the seed. This is almost certainly a really derpy pRNG.

Our seed value is... 7, according to the first website the Google search returned. An immediate problem occurs, because we just hit a repeating 0. How? Modulus 7 by 7, you get 0. (0 * (0 * 4))...Well, anyway. Change that to itself + 1; (itself * (itself * 4)). So 0 + 1; 1 * ( 1 * 4) = 4. Modulus 4 by 7 = 4.

4 + 1 = 5; 5 * (5 * 4) = 100. Modulus 100 by 7 = 2.

2 + 1 = 3; 3 * (3 * 4) = 48. Modulus 48 by 7 = 6

So we've just generated the sequence 0, 4, 2, and 6 from our initial seed value. Let's take it a couple steps farther...

6 + 1 = 7; 7 * (7 * 4) = 196. Modulus 196 by 7 = 0, which is unsurprising when your prime factors are 7, 7, 2, and 2. Heh.

So the period of this pRNG is 0, 4, 2, and 6. This is a terrible pRNG; it's period is 4 numbers long for a seed of 7, and all of them are **even.

And that brings us to the qualities of a good pRNG:

1) A good pRNG must have a "long enough" period for any seed number it could encounter.

2) A good pRNG must have a "random enough" period for any seed number it could encounter. That is, not only long enough, but also appear "patternless" over long enough periods of time. This includes the pattern of

*appearing patternless*. Don't worry, I'll explain that latter, if you want to know. Just put it aside for now.

3) A good pRNG is made by mathematicians and programmers. That is, people who are both mathematicians and programmers, and whose knowledge in this area took years and, generally, a Ph.D to acquire. And sometimes teams of such people.

So don't worry about understanding it; just copy the code and implement it in your language of choice. At this point, you should have enough info to get the general idea, and while the facts, fields, and subjects behind a good pRNG are very complex and deep, a pRNG framework is just "modulo by prime number, then apply math to get next seed", possibly with some other math bits happening to the seed or return value. But the case of pRNGs is one of the very rare cases where it really is ok to just copy the code and implement it without understanding more than the basics.

Which brings us to cryptography, which relies heavily on pRNG, and which you should never copy code for. Because you will make a mistake. When it comes to cryptography, the rules are, 1) Don't touch anything; 2) Import a cryptographic library; 4) Don't touch anything; 3) Use it properly; 4) Don't touch anything.

Anyway, if you got this far, a pRNG that looks very patternless actually looks less random, because random numbers occasionally look like they have a pattern. In a population of 7 billion, someone rolling 5 1's in a row is not only inevitable, there's a very high chance it's happening right now. By the way, never play someone who knows as much about statistics as I do in a game of chance if money is involved. I don't gamble, but people who do can take you to the cleaners. There's nothing that combines such happiness and annoyance in quite the same way as learning that, predictably, the people you are playing monopoly with believe in "lucky dice", "lucky numbers", or "luck anything".

Worse interpretation of statistics I've ever seen: Constantly interpreting "unlikely" as "it doesn't happen". No; it just means it happens less often. "But it happened to me; therefore it's not unlikely". Ok; if we take a random sampling of a thousand other people, how many of them did it happen to, and what other factors might account for that?

* Integer divide and return the remainder.

** Let's not quibble over whether 0 is actually divisible by 2 or not; or whether or not it's a number at all. Real mathematicians get headaches from that.