pen • chant
- a strong or habitual inclination.
- a tendency to do something.
- a taste or liking for a person or thing.
Penchant is a simple and effective random number generation plugin. Random number generation is integral to video game development, from item drops, to terrain generation, to procedural soundscapes. Sometimes, consistency of random numbers is necessary either for testing, balance, or reproduction purposes. Penchant aims to provide a simple solution to both generate and reliably reproduce seeded random values.
- Install the latest release from the GitHub repository, unzip it, and place the folder into your Unity project's
Packages
folder. - Return to Unity, and the package should automatically be recognized and visible in the Package Manager.
- A sample scene can be found at:
Penchant/Example/Example.unity
. - Opening this scene may prompt you to install Text Mesh Pro. Simply click on Import TMP Essentials to do so.
- To begin generating random numbers, simple create a new
SeededRandom
object with your desired seed, and get the object'sRandomValue
. Your seed can be any string. - You may wish to create multiple
SeededRandom
s if you have multiple systems in your game (e.g. a random enemy spawn system and a random item reward system) - The
SeededRandom
class comes with other methods for generating useful random object types (e.g.RandomRange
,RandomVector3
RandomRotation
) - If at any time you want to reset a
SeededRandom
, so that it starts generating numbers from the beginning again, simple useSeededRandom.Reset()
. - Lastly, to preview seeds and their distributions, use the
Penchant Visualizer
, which can be accessed in the menu bar viaPenchant/Visualizer
.
Example:
var enemySpawnSeededRandom = new SeededRandom("enemies");
var itemDropSeededRandom = new SeededRandom("items");
for (int i = 0; i < enemyCount; i++)
{
EnemyController enemy = Instantiate(
enemyPrefab,
enemySpawnSeededRandom.RandomVector3 * arenaSize,
enemySpawnSeededRandom.RandomQuaternion);
enemy.itemDrop = itemDropSeededRandom.RandomEntry(itemDrops);
}