Generate spec-compliant version strings
The Semantic Version Generator produces version strings that follow the semver.org grammar exactly: a MAJOR.MINOR.PATCH core, an optional pre-release after a hyphen, and optional build metadata after a plus sign. Use it to seed a package registry, populate a release dropdown, or feed a version parser realistic input during testing.
How it works
A semantic version has three required numeric components separated by dots. The tool draws each of major, minor and patch as a non-negative integer inside the range you choose. When the pre-release option is on, it appends a hyphen followed by an identifier such as alpha, beta or rc and a dot-numbered counter — for example -beta.2. When build metadata is on, it appends a plus sign and a short token such as a date or a fake commit hash.
Precedence rules matter: per the spec, a version with a pre-release has lower precedence than the same core version without one, and build metadata is ignored entirely for comparison. The generated strings respect that grammar so they parse cleanly in tools like npm, Cargo, or any ^semver library.
The semver grammar at a glance
MAJOR.MINOR.PATCH[-pre-release][+build-metadata]
Examples:
1.0.0
2.4.1-alpha.1
3.0.0-rc.2+sha.a1b2c3
0.9.0-beta.12+20260606
Each part has a specific role:
| Segment | Meaning | Comparison |
|---|---|---|
| MAJOR | Breaking change | Higher = incompatible |
| MINOR | New backwards-compatible feature | Higher = more capable |
| PATCH | Bug fix | Higher = more stable |
| Pre-release | Unstable build marker | Lower precedence than release |
| Build metadata | Traceability info only | Ignored by spec |
Common use cases for generated versions
Test fixture seeding. If you are writing a library that parses or compares version strings, you need a corpus of valid inputs. Generating fifty varied versions — some with pre-releases, some with build metadata, some at 0.x, some in the hundreds — exercises the full grammar rather than just the happy path.
Changelog and release-notes prototyping. When designing a changelog UI or a release dropdown, realistic version strings look very different from version1, version2, version3. Generated strings with proper semver structure help you catch layout issues with long pre-release tags or wide patch numbers.
Migration and upgrade tooling. Tools that suggest upgrades (for example npm’s --legacy-peer-deps resolver or Renovate-style bots) need plausible “from” and “to” version pairs to test their logic. Seeding those pairs from this generator avoids having to hardcode fixtures by hand.
Tips and example
- A plain release looks like
3.7.0. A pre-release looks like3.7.0-rc.1. A fully decorated string looks like3.7.0-rc.1+build.42. - Keep major at
0to model pre-1.0 software, where the public API is considered unstable by convention. - Build metadata never affects ordering, so use it only for traceability such as a date stamp or short commit hash — not to signal version priority.
- All values are synthetic — never treat a generated version as the real release number of any real package.