← Back to Documentation

Math API

⚠️ Experimental - Pre-Release

The Math API provides methods for random number generation and mathematical operations.

Methods

Math.random() → float

Returns a random float between 0.0 and 1.0.

var random_value = Math.random()Console.print("Random: " + random_value)

Math.random_range(min: float, max: float)float

Returns a random float between min and max (inclusive).

var random_x = Math.random_range(0.0, 100.0)var random_speed = Math.random_range(50.0, 150.0)

Math.random_int(min: int, max: int)int

Returns a random integer between min and max (inclusive).

var random_damage = Math.random_int(10, 20)var random_index = Math.random_int(0, 5)

Usage Example

@script Enemy extends Sprite2D    fn init() {        // Random position        self.transform.position.x = Math.random_range(0.0, 800.0)        self.transform.position.y = Math.random_range(0.0, 600.0)         // Random health        var health = Math.random_int(50, 100)    }     fn take_damage() {        var damage = Math.random_int(10, 25)        // Apply damage...    }