Common operations

by NullQuery
Commonly used operations
ID:2076044
 
A new version to my "Common operations" library has just been released that offers platform-independent random number generation using the Marsenne Twister algorithm.

Example usage:
// You can create multiple /nq_rand objects.
// This is useful if you want to provide your own
// seed values and don't want other code from
// interfering with your random number generation.
var/nq_rand/r = new

// Alternatively you can pre-initialize with a seed.
// This is for convenience; it just calls the
// r.Seed proc after creation.
// var/nq_rand/r = new(12345)

// You can modify the seed at any point.
// r.Seed(12345)

// Set the maximum amount of decimal points in the
// result. (Defaults to 5.)
r.MaxDecimals(0)

// Stores a random number between 1 and 5 (inclusive).
var/n = r.Random(1, 5)

Note that presently this algorithm is not faster than DM's built-in rand() proc but it is platform independent. It is intended to be used in situations where you want to store the seed value for later duplication of the same "random" values (e.x., random map generation).

As usual the source-code is available in my repository on Github. If you have any ways to improve any of my libraries feel free to let me know and I'll add it to a new release.
The fact that we don't actually have a built-in method of seeding RNG's is a bit saddening, but well done!
In response to Kats
Kats wrote:
The fact that we don't actually have a built-in method of seeding RNG's is a bit saddening, but well done!

There is a built-in method with rand_seed(), but AFAIK it's unpredictable because if the current proc sleeps another proc may call rand() and taint the results of the first proc. Also according to the docs it's platform dependent and will yield different results on Windows and Linux environments.
In response to NullQuery
Shit... I've been out of touch for too long. It's never been something I've had a use for before. Never really done anything with procedural generation or the like. Haha.