math.jamo (built in)

math: square roots, angles, powers, rounding, smallest and largest, and random numbers. use "math.jamo"

The random generator keeps its state in math_state, and math_seeded says whether it has been seeded yet.

The generator is a 64-bit LCG with Knuth's MMIX numbers, which wraps the way Jamo's ints do. Jamo has no bit operators, so xorshift would be slow. An LCG's low bits repeat quickly, so only the top 32 bits of each step are used.

funcpi

func pi(): float

funcabs

func abs(value: float): float

The size of a float, without its sign

funcabs_int

func abs_int(value: int): int

The size of an int, without its sign. The smallest int has no positive partner, so it comes back as it is

funcmath_check_fits

func math_check_fits(value: float, name: string)

funcfloor

func floor(value: float): int

The nearest int at or below

funcceil

func ceil(value: float): int

The nearest int at or above

funcround

func round(value: float): int

The nearest int. Halves round away from zero, so 2.5 gives 3 and -2.5 gives -3

funcmin

func min(a: float, b: float): float

funcmax

func max(a: float, b: float): float

funcclamp

func clamp(value: float, low: float, high: float): float

funclerp

func lerp(a: float, b: float, part: float): float

The value part of the way from a to b: lerp(0.0, 10.0, 0.25) is 2.5. Past 0.0 to 1.0 it goes beyond them

funcmin_int

func min_int(a: int, b: int): int

funcmax_int

func max_int(a: int, b: int): int

funcclamp_int

func clamp_int(value: int, low: int, high: int): int

funcrandom_seed

func random_seed(seed: int)

Starts the same numbers over again: the same seed always gives the same numbers

funcmath_seed_from_clock

func math_seed_from_clock()

funcmath_top_bits

func math_top_bits(value: int): int

The top 32 bits of a 64-bit value, as a number from 0 to 4294967295

funcmath_random_bits

func math_random_bits(): int

The generator's next 32 random bits

funcrandom_int

func random_int(low: int, high: int): int

A whole number from low to high, both included. Every number is equally likely

funcrandom_float

func random_float(): float

A float from 0.0 up to, but not including, 1.0

funcpick

func pick<T>(items: [T]): T

One item, picked at random

funcshuffle

func shuffle<T>(items: [T])

Puts the items in a random order, in place, with every order as likely (Fisher-Yates)