Function: IRandom
Function: IRandom

Function: IRandom

IRandom ( NUMBER )

Returns a random positive integer up to (but not including) the provided value.

Parameters

Parameter Type Description
NUMBER VALUE(INTEGER) The upper bound integer.

Returns

VALUE(INTEGER) A random positive integer.

What It Does

This function returns a random integer from 0 up to (but not including) the provided value. The input value, if it is not an integer, is interpreted as an integer.

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

FRandom() — Returns a random floating-point value.
GRandom() — Returns a random floating-point value with Gaussian distribution.

Additional Technical Notes

Authors can expect the distribution of this random number generator to be uniform.

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