Function: GRandom
Function: GRandom

Function: GRandom

GRandom ( MEAN, STDDEV )

Returns a random floating-point value starting from the mean with Gaussian distribution.

Parameters

Parameter Type Description
MEAN VALUE(FLOAT) The distribution mean.
STDDEV VALUE(FLOAT) The standard deviation from the mean.

Returns

VALUE(FLOAT) A random floating-point value.

What It Does

This function returns a random floating-point value from negative infinity to positive infinity, with Gaussian distribution centered on the mean, with a specified standard deviation. The input values, if they are not floating-point, are interpreted as floating-point.

Most uses of this function would for approximating multiple independent random values, as the combined distribution around such a task is a Gaussian (or "bell") curve. This means that there's a greater chance that values will be selected closer to the mean then any other part of the numeric continuum.

A mean of 0 and standard deviation of 1 would give you most results around the range of to , on average.

Example

NOTE: The following code will return different values every time it is executed!

Random Function Examples


world
{
	start()
	{
		local a;
		a = 10;
		textln("Generating " + a + " integers from 0 to 9:");
		while (a > 0)
		{
			textln(irandom(10));
			a = a - 1;
		}
		textln("");

		a = 10;
		textln("Generating " + a + " floats from [0.0, 1.0):");
		while (a > 0)
		{
			textln(frandom());
			a = a - 1;
		}
		textln("");

		a = 10;
		textln("Generating " + a + " Gaussian floats, mean 0, std. dev. 1:");
		while (a > 0)
		{
			textln(grandom(0, 1));
			a = a - 1;
		}
		
		quit;
	}
}

See Also

IRandom() — Returns a random integer value.
FRandom() — Returns a random floating-point value.

Additional Technical Notes

The method of generating random numbers is up to the TAME implementation (Java, JS, etc.), and the generator has not been standardized, yet.

There is currently no way to seed the random number generator for testing purposes, at the time of this writing.

×

Modal Header