The concept of permutations or combinations of objects is of taking a group of items or variables, and combining them in unique ways to create groups or sets of different items every permutation. The basic formula for a permutation is :
n! / (n - k)!
Where n is the pool of items (or characteristics), and k is the size of the sets you want to create, and the ! mark is used to donate a factorial, which is the sum of the number and all the numbers before it (so 4! is (4 * 3 * 2 * 1)). But permutation is not what is usually used when calculating things such as gun variants and the like, since with permutation, the order in which items are selected is important to the formula. So, say, if you were using this formula to create gun variants, you would end up with multiple copies of the same gun types, just with their characteristics entered into the "set" in different orders.
The more useful formula would be that of Combinations, where the ordering of items into sets is not important. The basic formula for combinations is :
n! / ( k! * (n - k)! )
Where again n is the pool of items, and k is the size of the sets you want to create. So for an example, say you have 15 different gun characteristics (like bonus accuracy, fire damage etc...) and you want each gun to only have 4 of these special characteristics. Then, using combinations, you have a possible 1365 gun combinations (where n is 15 and k is 4).
Use in Games
In videogames, where there is a need for many random and non-important NPCs, or many slight variations of the same basic frameworks, designers and artists will not create hundreds of different outfits and items by hand. Instead, they will use assets, such as the clothes the NPC will wear, and characteristics of the items they want to apply to the aforementioned basic frameworks, and randomly created those objects through algorithms that will assign different combinations of characteristics to that object.
So, for an example, take Borderlands
, with its promise of zillions of guns. As you know if you have played the game, most guns are quite similar in look and there are basic frameworks (pistol, assault rifle etc...) that each gun will fall into. But then there are the special attributes of most guns, like being able to fire multiple shots at a time, or elemental damage. That is where combinations come in. The game will have a pool of these characteristics, and when you are about to open a gun crate, or an enemy is about to drop a gun, the game will retrieve a set of those characteristics, specified by what the game wants at the time, and assigns them to that weapon on the spot. Using these types of algorithms, Borderlands can randomly and easily create many different guns throughout the game.
Another good example is the Left 4 Dead
games and GTA 4
, with their is a need for many characters onscreen at a time and the need for them to be all unique. The assets in this case are the body types, and clothes. So when you're driving around in GTA 4, when those civilians that are always around are created, the game will retrieve sets of these objects (a set being body type, hair color, shirt, hat etc...) and through combinations, the game will be able to have many different characters onscreen whilst still having each character be unique.
If you ever want to see a game where these techniques and algorithms could have been put to good use, look at Dead Rising. This is a game with many zombies onscreen at a time. But if you ever take a good look at a significant group of zombies, you will see many zombies that look practically identical. This is because I believe the designers went by hand and created a handful of zombies, instead of using a combination type approach. This is why you will see many duplicates in the same crowd when playing Dead Rising, because the game only has a handful of predetermined character looks, instead of being able to randomly created these zombies on the spot.