0

I am working on a smart contract that need to pick true or false value (or any two value) with percentage. For example in 95% selects true but in 5% selects false. Can I do that in my contract?

1 Answer 1

0

You can use Chainlink VRF, which is the current industry standard for generating random numbers on Solidity. You could use it to generate a random number within the range 0-100, here's a simple guide that shows how to do so. You would only need to change the range to be as follows:

randomResult = (randomness % 100);

To get a boolean value with a percentage probability. For example, true with 95% probability. You would only need to follow up with the following check:

bool val = randomResult <= 95;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.