Skip to content

DillonEnge/buid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

BUID - Billiards Unique Identifier

Go Version

A unique identifier generator that uses physically simulated billiards breaks to create cryptographically unique IDs.

What is BUID?

BUID (Billiards Unique Identifier) generates unique identifiers by simulating a billiards break shot using real physics. Each ID generation creates a virtual pool table with 28 balls arranged in a triangle formation, then strikes them with a cue ball at randomized velocity. The final positions of the balls after the physics simulation completes are used to generate a unique alphanumeric identifier.

Key Features

  • Physics-Based Randomness: Uses the Chipmunk2D physics engine for realistic ball interactions
  • Low Collision Rate: Only 0.08% chance of generating duplicate IDs
  • Deterministic from Input: Same velocity input produces same ID (useful for testing)
  • Alphanumeric Output: Generated IDs contain digits (0-9), uppercase (A-Z), and lowercase (a-z) characters
  • High Performance: Capable of generating thousands of IDs per second

How It Works

  1. Setup: Creates a 60x60 unit virtual pool table with walls
  2. Ball Arrangement: Places 28 balls in a triangular rack formation
  3. Break Shot: A cue ball strikes the rack with randomized velocity (45-95 X, ±4 Y)
  4. Physics Simulation: Runs for 10 seconds of simulated time (600 physics steps)
  5. ID Generation: Maps final ball positions to alphanumeric characters

The physics simulation includes:

  • Realistic ball elasticity (0.95)
  • Friction between balls and table (0.03)
  • Energy dampening (0.5) to settle the balls
  • Collision detection and response

Installation

go get github.com/DillonEnge/buid

Usage

Basic Usage

package main

import (
    "fmt"
    "log"
    
    "github.com/DillonEnge/buid"
)

func main() {
    id, err := buid.New()
    if err != nil {
        log.Fatal(err)
    }
    
    fmt.Println("Generated BUID:", id)
}

Example Output

Generated BUID: Qmd9RveLdVYbYDfSfdVlfJgNiSleZlmDiLkQkZmbikqCqFlOqSlVtZcr

Performance

The criteria, features and results of a locally run benchmark (M3 Macbook Pro) were as follows:

  • Throughput: 10,000 IDs generated in parallel
  • Collision Testing: Duplicate IDs tracked across generations
  • Timing: Total operation time recorded

Benchmark output:

op time: 9.341s
id conflicts: 0.08%

Dependencies

Technical Details

Physics Parameters

  • Table Size: 60x60 units
  • Ball Diameter: 2 units
  • Ball Count: 28 balls + 1 cue ball
  • Simulation Time: 10 seconds (600 steps at 60 FPS)
  • Ball Elasticity: 0.95
  • Table Friction: 0.03
  • Damping: 0.5

Why Physics-Based IDs?

Traditional UUID generators typically rely on timestamps, random numbers, or MAC addresses. BUID takes a novel approach by leveraging chaotic physical systems. Even tiny changes in initial conditions (cue ball velocity) result in dramatically different final ball arrangements, providing natural entropy and uniqueness.

The billiards simulation creates a deterministic but chaotic system where:

  • Small input changes create large output differences
  • The physics engine ensures realistic ball interactions
  • Multiple collision events amplify initial randomness
  • Final positions provide high-entropy state for ID generation

"A new style of ID generation, with a humourous twist"

About

BUID is a unique identifier generation package using a billiards break physics simulation written in Go

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages