Jump to content
Existing user? Sign In

Sign In



Sign Up

[Ruse] Percentage chance boolean


Flub

Recommended Posts

Hey guys.

I see far too many servers using this method to generate percentage chance;

int chance = 10;
if (Misc.random(100) <= chance){
    doSomething;
}

I made this one to simplify things:

public static double randomDouble(double i) {
        return getRandomDouble(i);
    }

public static boolean percentageChance(double percentage) {
        return percentage >= randomDouble(100);
    }

You need the random double method in order for for the percentage chance to work. Shove them into Misc.java or something.

Use like this (This example is generating a 10% chance)

if (Misc.percentageChance(10.0)) {
            doSomething;
        }

 

Noice

Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...
  • 1 month later...
  • 3 months later...
  • 4 months later...
  • 3 months later...
  • 5 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Contact

[email protected]

astra.security

What is a RSPS?

A RSPS, also known as RuneScape private server, is an online game based on RuneScape, and controlled by independent individuals.

Popular RSPS Servers

Runewild Ikov RedemptionRSPS

Disclaimer

Runesuite is not affiliated with runescape, jagex in any way & exists solely for educational purposes.

×
×
  • Create New...