Get just one random permutation - adamjgrant/permutations GitHub Wiki
Often, you'll only need one permutation from the whole set, and randomly selected.
This is also useful if you have a permutation whose full set is so large, it would be computationally expensive or even impossible to run the full set.
An easy example is a simple hex color generator:
const data = {
"main": [{
"branch": "hex", "then": {
"branch": "hex", "then": {
"branch": "hex", "then": {
"branch": "hex", "then": {
"branch": "hex", "then": {
"branch": "hex"
}
}
}
}
}
}],
"hex": ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
}
Just call .one
on the permutation tree instance to get a single random permutation.
const tree = new Permute(data, true);
const permutations = tree.one;
console.log(permutations);
Output
['55DD95']