🌽 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)
const generateId = createSandcornGenerator();

// Generate a unique ID
const id = generateId();
console.log(`Generated ID: ${id}`);

// Decode an ID to see its components
const decoded = decodeSandcorn(id);
console.log(`Created on computer ${decoded.machineId} at hour ${decoded.tick}`);
const generateId = createSandcornGenerator();

// Generate an ID with a specific timestamp
const customTime = Math.floor(os.epoch() / 3600);
const id = generateId(customTime);

Sandcorn assumes your computers have unique IDs and relatively synchronized clocks. Time drift between computers may affect ID ordering.

Functions

createSandcornGenerator
decodeSandcorn