Details on this library here:
https://github.com/Croc-Prog-github/Probability-Manager.js
const probManager = new ProbabilityManager(); // Creation of instances and lists probManager.addList('Instance1', '1'); // Adding objects with probability probManager.addObject('Instance1', '1', 'Gold coin', 15); probManager.addObject('Instance1', '1', 'Silver coin', 35); probManager.addObject('Instance1', '1', 'Bronze coin', 50); // Extraction of a random object let randomEvent = probManager.getRandomObject('Instance1', '1'); console.log(`Extracted object: `+ randomEvent); const arrayRepresentation = probManager.toArrayForInstance('Instance1'); console.log(arrayRepresentation); // Cleanup of instances probManager.clearInstance('Instance1');
Edit the example for run it: add an Enter or a Space.
Run