| 111 | }; |
| 112 | |
| 113 | const getRandomRarity = (_rarityOptions) => { |
| 114 | let randomPercent = Math.random() * 100; |
| 115 | let percentCount = 0; |
| 116 | |
| 117 | for (let i = 0; i <= _rarityOptions.length; i++) { |
| 118 | percentCount += _rarityOptions[i].percent; |
| 119 | if (percentCount >= randomPercent) { |
| 120 | console.log(`use random rarity ${_rarityOptions[i].id}`) |
| 121 | return _rarityOptions[i].id; |
| 122 | } |
| 123 | } |
| 124 | return _rarityOptions[0].id; |
| 125 | } |
| 126 | |
| 127 | // create a dna based on the available layers for the given rarity |
| 128 | // use a random part for each layer |