Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • Weighted Random Numbers

    Hyper Crusher

    Recommended Posts

    This is just a simple utility that offers random numbers within a range, with the option to provide a bias.

    When working on scripts I prefer to have the bot wait between 600-900ms if an action has been completed or after opening the bank for example, rather than always waiting the same amount of time I like to choose a random number between these. I also prefer to have a bias applied since an even distribution is inhuman in nature and anything that says "I am a bot" is something I would like to avoid. The class can be included anyway in your project, all of the methods are static so you do not need an object instance to call them.

    All functions return int


    To clarify this is just a wrapper for  java.util.Random().nextInt((max - min) + 1 ) + min;

    Random.nextInt(int min, int max);

    Lower 'weight'

    Random.low(int min, int max);

    Mid-point 'weight'

    Random.mid(int min, int max);

    Higher 'weight'

    Random.high(int min, int max);

    Custom 'weight'

    for reference deviation for all functions is 0.3 of the difference of max and min

    Random.nextGaussian(int min, int max, double deviation, double mean);

    Data set

    I ran all functions 20,000 times, and plotted the points on a graph. X-axis is the number generated and the Y axis is the number of times that number showed up

    Low Bias:


    Mid-point Bias:

    High bias


    Edited by Hyper Crusher
    Updated with latest version
    Link to comment
    Share on other sites

    On 11/7/2019 at 6:20 AM, Neffarion said:

    You can also use Gaussian random if bias is what you are seeking. Its probably even more natural

    // From 300 to 900 with "bias" of 600

    That does work, but I personally prefer being able to set lower, and upper limits :)

    if your looking for just a way to ensure a bias towards one number or another it works great though. I want to eventually do it with a Gaussian function, but for some quick goings this is working reasonably enough. I'm new to DreamBot, so I'm still fumbling my way through the API and testing different features :)

    Edited by Hyper Crusher
    Link to comment
    Share on other sites

    I can't seem to figure out how to edit the main post, (or my reply where I merged my response and the quote, my bad)

    So here is an update :D


    I went ahead and decided that normal distribution was the way to go, so I spent some time working out a deviation and mean that I think worked with what I was trying to go for when I quickly wrote this up

    main post now reflects this update

    Edited by Hyper Crusher
    Link to comment
    Share on other sites

    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

    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.