🎲 Generate random CVSS vectors for test data
Problem
You need CVSS vectors to seed a test database, write property-based tests, or demo a dashboard — but hand-writing valid vectors is tedious and biased toward a few familiar shapes.
Solution
Here's the flow:
CLI: random
cvss random emits a valid, base-only v3.1 vector with uniformly random metric values:
cvss randomCVSS:3.1/AV:A/AC:L/PR:H/UI:R/S:C/C:N/I:L/A:HEach call is different. Useful flags:
cvss random --score # include the calculated score
cvss random --temporal # add E/RL/RC
cvss random --full # add temporal + environmental
cvss random --cvss-version 3.0 # v3.0 instead of v3.1
cvss random --format json # {"vector": "..."}cvss random --scoreCVSS:3.1/AV:A/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:N
Score: 7.1 (High)cvss random --temporalCVSS:3.1/AV:A/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:L/E:H/RL:T/RC:Rcvss random --format json{
"vector": "CVSS:3.1/AV:L/AC:H/PR:H/UI:R/S:C/C:H/I:N/A:H"
}Generate a batch by looping:
for i in $(seq 1 5); do cvss random; done > fixtures.txtGo SDK: mock.RandomCvss3xFull
The pkg/mock package gives you objects directly, so you don't have to parse the string back. RandomCvss3x is base-only, RandomCvss3xWithTemporal adds E/RL/RC, and RandomCvss3xFull adds all 11 environmental metrics. The argument is the minor version (0 or 1).
package main
import (
"fmt"
"github.com/scagogogo/cvss-skills/pkg/mock"
)
func main() {
// Base-only v3.1.
fmt.Println(mock.RandomCvss3x(1).String())
// Full (temporal + environmental) v3.1.
full := mock.RandomCvss3xFull(1)
fmt.Println(full.String())
// With score.
cv, score, err := mock.RandomCvss3xWithScore(1)
if err != nil {
panic(err)
}
fmt.Printf("%s -> %.1f\n", cv.String(), score)
// v3.0 random vector string.
fmt.Println(mock.RandomCvss3xVectorString(0))
}A sample run:
CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:C/C:N/I:H/A:L
CVSS:3.1/AV:L/AC:H/PR:N/UI:R/S:C/C:N/I:H/A:L/E:X/RL:W/RC:R/CR:L/IR:L/AR:M/MAV:X/MAC:H/MPR:H/MUI:N/MS:C/MC:X/MI:H/MA:L
CVSS:3.1/AV:A/AC:L/PR:H/UI:N/S:U/C:L/I:H/A:N -> 5.3
CVSS:3.0/AV:P/AC:H/PR:H/UI:N/S:C/C:N/I:L/A:NReproducible randomness
pkg/mock uses math/rand without seeding. For deterministic test fixtures, seed the global source (rand.Seed(42)) at the start of your test, or capture generated strings into a golden file once and check that in.
Discussion
- Every generated vector is valid and scoreable.
RandomCvss3xFullsets every metric to a legal value, soNewCalculator(cv).Calculate()never errors on its output. - Distribution is uniform per metric, not over scores. Because each metric is chosen independently, the score distribution is not uniform — extreme scores (0.0, 10.0) are rarer than mid-range ones. If you need a vector at a specific severity, build it with
buildor use a preset. --fullcan includeX(Not Defined). Environmental metrics include theXvalue, which the calculator treats as "inherit the base metric" — so a full random vector still scores sensibly.- Not what you want? For a fixed vector at a known severity, use the
presetcommand orcvss.CriticalV31()/HighV31()/MediumV31()/LowV31()/NoneV31()in Go.
See Also
random— the CLI commandpreset— fixed-severity vectors- Mock & Random —
RandomCvss3x/RandomCvss3xFull/RandomCvss3xWithScorereference - Presets —
CriticalV31and friends - Store in a database