This question evaluates understanding of combinatorics, deterministic pseudo-random generation, and efficient enumeration for producing unique NFT metadata, measuring competency in algorithm design, state-space management, and handling large-scale outputs.
You are implementing an NFT metadata generator. Each NFT is defined by selecting exactly one trait value from each trait category. You must generate a requested number of NFTs, ensure they are unique (no repeated trait combinations), and output JSON metadata.
A single JSON object with:
collectionName
(string)
traits
: an array of trait categories. Each category is:
name
(string)
values
(array of strings, non-empty)
n
(integer): number of NFTs to generate
seed
(integer): seed for deterministic pseudo-random generation
Example:
{
"collectionName": "MyCollection",
"traits": [
{"name": "Background", "values": ["Blue", "Red"]},
{"name": "Eyes", "values": ["Normal", "Laser"]}
],
"n": 3,
"seed": 42
}
seed
to make generation deterministic:
n
exceeds the number of possible unique combinations, output
ERROR
.
Output a JSON array of length n. Each element is an object:
name
:
"<collectionName> #<index>"
where
index
starts at 1
attributes
: array of
{ "trait_type": <categoryName>, "value": <selectedValue> }
Example output element:
{
"name": "MyCollection #1",
"attributes": [
{"trait_type": "Background", "value": "Red"},
{"trait_type": "Eyes", "value": "Laser"}
]
}
n
can be up to 100,000.
You must define your own approach for generating unique combinations efficiently (not by repeatedly sampling and retrying until unique).