Files
2026-08-31 16:28:12 +07:00

1.4 KiB

prime-generator

Generates every prime from 0 up to a limit with the sieve of Eratosthenes and writes them one per line to a text file. The default limit is 1,000,000,000.

Originally written in Java. In 2026 it was rewritten in Go; the Java version is on the feature/java branch.

Requirements

  • Go 1.25 or higher
  • Disk space for the output — a full run to 1,000,000,000 writes 50,847,534 primes, roughly 500 MB
  • About 1 GB of RAM at the default limit, since the sieve holds one byte per number

Usage

go run .

Or build a binary first:

go build -o prime-generator .
./prime-generator

Flags

Flag Default Purpose
-n 1000000000 Upper limit, inclusive, to sieve
-out primes.txt Output file path
# Primes below 100, written somewhere else
./prime-generator -n 100 -out small.txt

Tests

go test ./...

The sieve is checked against an independent trial-division implementation, and against the published prime counts at powers of ten up to 1,000,000 — so a bug in the sieve is not mirrored by the thing checking it.

crawl-prime reaches the same output file from the other direction: it downloads a published prime list instead of computing one.