Index of every page on this site: llms.txt
All skills
jame581 avatar

/math-essentials

@426e8ab
by Jan Mesarčjame581/godotprompter979 stars
63
Run it yourself

Use when implementing game math — vectors, transforms, interpolation, curves, random number generation, and common geometric recipes

Use this Skill: https://skilld.dev/gh/jame581/godotprompter/math-essentials

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesrandom-numbers.md

≈742 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Random Number Generation

Reference for skills/math-essentials/SKILL.md — global random functions, RandomNumberGenerator (seeded), weighted random selection, noise (procedural generation).

← Back to SKILL.md


5. Random Number Generation

Global Functions

var f: float = randf()                    # 0.0 to 1.0
var i: int = randi()                      # 0 to 2^32 - 1 (unsigned 32-bit)
var ranged: float = randf_range(1.0, 10.0)  # 1.0 to 10.0
var ranged_int: int = randi_range(1, 6)   # 1 to 6 (inclusive)
float f = GD.Randf();
uint i = GD.Randi();                               // 32-bit unsigned
float ranged = (float)GD.RandRange(1.0, 10.0);     // double overload: 1.0 to 10.0
int rangedInt = GD.RandRange(1, 6);                // int overload: 1 to 6 (inclusive)

RandomNumberGenerator (Seeded)

For deterministic, reproducible randomness (procedural generation, replays).

var rng := RandomNumberGenerator.new()
rng.seed = 12345  # same seed = same sequence every time

var value: float = rng.randf_range(0.0, 100.0)
var roll: int = rng.randi_range(1, 20)
var normal: float = rng.randfn(0.0, 1.0)  # Gaussian distribution
var rng = new RandomNumberGenerator();
rng.Seed = 12345;

float value = rng.RandfRange(0.0f, 100.0f);
int roll = rng.RandiRange(1, 20);
float normal = rng.Randfn(0.0f, 1.0f);

Weighted Random Selection

# Weighted random pick from a loot table
func weighted_random(table: Array[Dictionary]) -> Dictionary:
    # table = [{"item": "gold", "weight": 60}, {"item": "gem", "weight": 30}, {"item": "rare", "weight": 10}]
    var total_weight: float = 0.0
    for entry in table:
        total_weight += entry["weight"]

    var roll: float = randf() * total_weight
    var cumulative: float = 0.0
    for entry in table:
        cumulative += entry["weight"]
        if roll <= cumulative:
            return entry

    return table.back()
public Godot.Collections.Dictionary WeightedRandom(Godot.Collections.Array<Godot.Collections.Dictionary> table)
{
    float totalWeight = 0.0f;
    foreach (var entry in table)
        totalWeight += (float)entry["weight"];

    float roll = GD.Randf() * totalWeight;
    float cumulative = 0.0f;
    foreach (var entry in table)
    {
        cumulative += (float)entry["weight"];
        if (roll <= cumulative)
            return entry;
    }
    return table[^1];
}

Noise (Procedural Generation)

var noise := FastNoiseLite.new()
noise.noise_type = FastNoiseLite.TYPE_SIMPLEX_SMOOTH
noise.frequency = 0.05
noise.seed = randi()

# Sample 2D noise at a position
var height: float = noise.get_noise_2d(x, y)  # returns -1.0 to 1.0
var noise = new FastNoiseLite();
noise.NoiseType = FastNoiseLite.NoiseTypeEnum.SimplexSmooth;
noise.Frequency = 0.05f;
noise.Seed = (int)GD.Randi();
float height = noise.GetNoise2D(x, y);

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts29d3 checks · Risk SAFE
  • Gen Agent Trust Hub29d

    The skill provides comprehensive documentation and code examples for game-related mathematics in Godot 4.3+, including vectors, transforms, and interpolation. No security issues or malicious patterns were detected.

  • Socket29d

    No alerts

  • Snyk29d

    Risk: LOW · No issues

Signed by skilld at 426e8ab. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 6 days ago.

Activeupdated last month

README badge

README badge for jame581/godotprompter/math-essentials