1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Taking a random percante from a config

Discussion in 'Development' started by Junkdude, Apr 22, 2019.

  1. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    So I'm currently working on a lucky plugin for someone, and I was wondering If it would be possible to take a percanteage(or a number) from the config and that's the chance of code executing. Would it be possible?
     
  2. KielKing

    KielKing Zombie

    Messages:
    245
    GitHub:
    kielking
    yes, you can use
    PHP:
    mt_rand(1100);
    as 1% to 100%, then check if rand result is less than or equal to the number on the config
     
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    How would I check it?
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Equate it to 100
    PHP:
    if(mt_rand(percentage100) === 100)
    But this wont work with floating percentages as you can already tell.
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.