Advertisement

Random Noise And Permutation?

Started by May 22, 2003 03:29 PM
6 comments, last by Bad Maniac 21 years, 9 months ago
I''ve recently fiddled around with perlin noise, as can be seen in the graphic forum. Now, someone mentioned making an array of random numbers, and using a permutation table. So I''d like some resonably clever person to explain to me what a permutation table is, how it works, and how to implement one. Links, explanations, pseudo code, or source are all welcome. Thanks in advance //Martin The more I think, the more confussed I get.
JRA GameDev Website//Bad Maniac
Is this "permutation" as in combinatorics, or is it supposed to be "perturbation?" I think I could figure out what a perturbation table does, but I have no clue what a permutation table is.
You know what I never noticed before?
Advertisement
I think that the user above has an incorrect idea of a permutation. A permutation is simply an order of an event. For example, if a pizza man is trying to deliver 10 pizzas to ten different houses there are 10! different ways he can deliver them. In other words, there are 10! different permutations. For example, the combination [A,B,C] can have several different permutations. Such as [B,C,A] and [A,C,B]. Usually permutations are used in problems concerning the order of an event. If you need more clarification email me at BioagentX@gdnmail.net.
There are three types of people in this world, those who can count, and those who can't
In the Perlin noise algorithm, the permutation table is just an array containing a random permutation of the numbers 0 through arraysize-1. A permutation table of size four could be {3,1,0,2} or any other ordering of those four numbers. It is just basically a lookup table.
Right, and how exactly is it used as a lookup table, could someone please explain the implementation quickly?
JRA GameDev Website//Bad Maniac
if you have a permutation table of size 128 called perm, and an integer x, you would use it as follows:

perm[x%128]

that simple. if you have multiple coordinates (as with 2d or 3d or even higher dimensional noise), you would use it like this:

perm[(perm[x%128]+y)%128]

The idea is you just give it an integer, and get an integer back. For any given integer, or coordinates, you always get the same number back. The permutation table can be easily created with a shuffle algorithm. There is a shuffle algorithm in the standard library if you want to use that.
Advertisement
I don''t know if you need this, but I think I can give you a more in depth explanation. Normally, you''d have a rand() function that gives you pseudorandom numbers, the same one for any given seed. An easier, faster way to do that is to precalculate your numbers, and then make the random seed just an index into the permutation table. That way, you get pseudorandom numbers without having to play around with a random number generator. I want to make a perlin noise system, but I can''t really find any information about RNGs, so I will probably just use a permutation table (and now I know what to call it!). I think I will make it pretty large, though. Probably 2^16.
You know what I never noticed before?
Actually, Perlin''s algorithm and his implementations use permutation tables. Pages that describe using a psuedorandom number generator are just confused, not to mention the fact that the number generators aren''t made to be seeded every time they are used and that doing it that way might make the numbers not quite as random.

Make the permutation table as big as you want a non-repeating section of it to be.

This topic is closed to new replies.

Advertisement