Modding:Random Functions

If your mod has some element of randomness, you're gonna be looking for a function to call. However, calling the built in  function in the Random Class built into C# will net you some compilation errors. The best practice is to use the random functions inside. Below are the different random functions inside Caves of Qud and what they are used for.

Randoms
These are the methods that return the Random class. These are all hashed from

Rnd
This is the main function that randomizes and determines things such as sultan artifacts, villages, and basically everything important that is based on world seed. All effects and mutations use this function. Don't use this function in your mod if you don't want to ruin world seeds.

Rnd2, Rnd4, Rnd5
These functions deals with the smaller events you find in Qud.

LevelUpRandom
The Random used to determine randomized things at level up.

GetSeededRandomGenerator(string Seed)
If you don't want to use the game's seeds in fear of altering worldseed too much, there is a helper function that returns a new random that hashes a new random. This allows your mod to be affected by world seed but does not alter the base game's random number calls. The Seed here should follow best practice conventions, so  to avoid overlapping conflicts as much as possible.

Returners
These use a specific random class to return a multitude of things.

Random(int low, int high)
Calls

TinkerRandom(int Low, int High)
Calls

GaussianRandom(float Mean, float StandardDeviation)
Returns a random float around the mean with a probability density of a normal distribution.

RandomCosmetic(int low, int high)
Used most often when getting random angles for particles and other cosmetic effects. Calls.

SeededRandom(string Seed, int Low, int High)
Returns an int based on, in the range of.

Sample Random Provider for Mod
Here is a fully usable out-of-the box random number provider for your mod, which will not interfere with the game's own random seeds.

This template provides:
 * a  property (direct access to the Random object)
 * a  method that returns a random number in the specified range

It also ties itself to each game's worldseed and automatically resets for new games or save loads.

Example Usage

 * 1) Save the code above in its own file (for example,  ).
 * 2) In your other mod code files, include the following using statment:
 * 3) Call the code in one of the ways demonstrated below.