'Solidity how to get random number with ratio

I want to create my own NFT according to ERC1155 standard.

My hero has 6 parts, each part has 4 types as shown in the picture.

Now I want to create a function that takes a random number with the ratio shown in the image.

Here is simple function return random number. With _mod = 10^n it will return number of length n-1.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract RandomNumbers{
    function random(uint _mod) public view returns(uint){
        return uint(keccak256(abi.encodePacked(block.timestamp,block.difficulty,  
        msg.sender))) % _mod;
    }
}

enter image description here

I've been struggling with this for a whole day. Thanks for help.



Solution 1:[1]

Just so you know. You shouldn't use keccak256(abi.encodePacked(block.timestamp,block.difficulty,msg.sender)) to generate a random number because that actually creates a pseudo-random guessable number. Take a look at Chainlink VRF.

For the ratio you could try to check out this Data structure (GitHub): you manually set values for the leaves and then when you have your random number you can call the draw function to set the different stats.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Niccolò Fant