The Javascript Set object doesn't have a random() function, nor does the SugarCube 2.x story format add a random() function to the Set object like it does to the Array object.
You can use code like the following within your story's Story Javascript area to create your own custom random() function on the Javascript Set object.
/*
* Returns a random value from the related set.
*
* Does not modify the original collection.
*/
Object.defineProperty(Set.prototype, 'random', {
configurable : true,
writable : true,
value() {
if (this == null) {
throw new TypeError('Set.prototype.random called on null or undefined');
}
return Array.from(this.values()).random();
}
});
note: you may want to get a more experienced Javascript programmer to look over the above in case it contains incompatibilities with older web-browsers.
The new custom random() function is uses as follows:
<<set $npc to {'options': new Set()}>>\
<<set $npc.options.add(1).add(3).add(5)>>\
options: <<= $npc.options>>
random: <<= $npc.options.random()>>
edit: altered <Set>.random() example based on TheMadExile suggestions.