Skip to content

The Maths Standard Library

C272 edited this page Dec 18, 2019 · 5 revisions

Contains most core mathematical functions and libraries for Algo.


maths.random.int()

Generates a random integer between the max negative INT32 and the max positive INT32 value.

Parameters:

No parameters.

Usage:

let x = maths.random.int();
print x; //random.

maths.random.intRange(min, max)

Generates a random integer between the given values (the values must be between the max negative INT32 and the max positive INT32).

Parameters:

Name Description
min The minimum value to generate.
max The maximum value to generate.

Usage:

x = maths.random.intRange(0, 10); //generates a number between 0 and 10
print x;

maths.modPow(base, pow, mod)

Raises a base value to a power, then performs a modulus on that value. Useful when values become too large to process.

Parameters:

Name Description
base The base number to apply the modPow to.
pow The power to raise to.
mod The value to modulus by.

Usage:

x = modPow(3, 213, 2); //same as 3^213 % 2

maths.isPrime(num, cert)

Checks whether a number is prime using the Miller-Rabin primality test, given a certainty.

Parameters:

Name Description
num The number to check for primality.
cert The certainty value. 5 is usually fine.

Usage:

print maths.isPrime(5, 5); //true
print maths.isPrime(20, 5); //false