function roll() external { gachaTicket.transferFrom(msg.sender, address(this), gachaCost); uint256 rand = _random(); uint256 stars; if(rand < 1) { stars = 5; } // 5* at 1% else if(rand < 5) { stars = 4; } // 4* at 4% else if(rand < 15) { stars = 3; } // 3* at 10% else if(rand < 50) { stars = 2; } // 2* at 35% else { stars = 1; } // 1* at 50% gachaCapsule.mint(msg.sender, stars); } function _random() internal returns (uint256) { return uint256(keccak256(abi.encodePacked(block.timestamp, block.number, msg.sender, gachaCapsule.totalSupply()))) % 100; }
0.4.18