🌽 A distributed unique ID generator for ComputerCraft computers
Sandcorn (like Snowflake, but for sand computers! 🏖️) generates unique, sortable IDs
that are perfect for distributed systems in ComputerCraft. Each ID contains:
Timestamp (hours since epoch)
Machine ID (your computer's ID)
Sequence number (for multiple IDs in the same hour)
Example: Basic Usage
constgenerateId = createSandcornGenerator();
// Generate a unique ID constid = generateId(); console.log(`Generated ID: ${id}`);
// Decode an ID to see its components constdecoded = decodeSandcorn(id); console.log(`Created on computer ${decoded.machineId} at hour ${decoded.tick}`);
Example: Custom Timestamp
constgenerateId = createSandcornGenerator();
// Generate an ID with a specific timestamp constcustomTime = Math.floor(os.epoch() / 3600); constid = generateId(customTime);
Warning
Sandcorn assumes your computers have unique IDs and relatively synchronized clocks.
Time drift between computers may affect ID ordering.
Description
🌽 A distributed unique ID generator for ComputerCraft computers
Sandcorn (like Snowflake, but for sand computers! 🏖️) generates unique, sortable IDs that are perfect for distributed systems in ComputerCraft. Each ID contains:
Example: Basic Usage
Example: Custom Timestamp
Warning
Sandcorn assumes your computers have unique IDs and relatively synchronized clocks. Time drift between computers may affect ID ordering.