Random Methods

Alexandre Dufresne 1 Reputation point
2021-02-11T15:22:11.54+00:00

Honeslty more of a statement then a question, don't you think you guys should do a random method for a percentage of chance to get a result and returns a bool accordingly? would be super easy, I could even code it for you.

bool PercentageChance(int percentage)
{
if(Next(0, 101) <= percentage)
return true;

return false;

}

you guys could even go as far as making a function for double also with NextDouble!

Don't you agree? I litteraly code this everytime in my projects.

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,525 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Alberto Poblacion 1,556 Reputation points
    2021-02-11T18:56:21.21+00:00

    It can be simplified a bit more. You don´t need an if to return a bool.

    bool PercentageChance(int percentage)
    {
        return Next(0, 101) <= percentage;
    }
    

    And yes, anyone who needs such a function can add it to their code.

    1 person found this answer helpful.
    0 comments No comments