Solved Percentages..

Discussion in 'Plugin Development' started by ItsOneAndTwo, Oct 13, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    ItsOneAndTwo

    Hey bukkit community, I've never tried to do anything with percentages in Java, so I was wondering, how would I do something with percentages?
    What I'm trying to do, is like for an example, there's 80% chance, that a player gets message "Hi", 5% chance of "What up?" and 15% chance of "Bye".
    How would I accomplish that?
     
  2. Offline

    Aqua

    create new Random object,
    do nextDouble(); this will return a value between 0 and 1.
    Now check if the given value is smaller than 0.80, if so, send "Hi",
    if value is between 0.80 and 0.85 send "What up?",
    if value is more than 0.85 send "Bye"
     
  3. Offline

    ItsOneAndTwo

    Aqua will give that a try, I'll mark this as Solved as soon as I'm done testing, thanks :)

    Aqua Thanks again for your time and help.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
Thread Status:
Not open for further replies.

Share This Page