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
  • Generating a hash based off of the current username [DB3]


    bap
     Share

    Recommended Posts

    Hey! I wanted to have sort of 'human profiles' to my scripts so I decided to get into username hashing and that username hash is the seed for a random number generator then you can base your profiles off of that number and it will always be the same :)

    Code:

        private String username;
        private long seed;
        Random random;
        private int number;
        private boolean shouldGenerateHash = true;
    
       @Override
        public int onLoop() {
            if (shouldGenerateHash) {
                if (Players.localPlayer() != null) {
                    username = Client.getUsername();
                    seed = UUID.nameUUIDFromBytes(username.getBytes(StandardCharsets.UTF_8)).getMostSignificantBits();
                    random = new Random(seed);
                    number = random.nextInt();
                    log("Random number based off of username: " + number);
                    shouldGenerateHash = false;
                }
            }
            log("Done");
            return Calculations.random(800,1150);
        }
                log("Random number based off of username: " + number);
                shouldGenerateHash = false;
            }
            log("Done");
            return Calculations.random(800,1150);
        }

    Still trying to get a way to have the numbers a bit lower somewhere around the 10,000's as now it generates way above that.
    This is what I got from my test:


    3:44:21 PM: [SCRIPT] Random number based off of username: 459183759

    I'd like it to be in the 10,000's or at least in the 100,000's so it's a bit more manageable to generate profiles for.

    Hope you guys like this snippet and that it comes in handy :) 

    Edited by notsmile
    It won't try and generate the hash at the login screen :P
    Link to comment
    Share on other sites

    You have to be really careful when generating random numbers, especially when using the same seed. You will always get the same "random" numbers in the exact same order every time you run something, which actually makes this example extremely detectable from a pattern detection perspective.

    What we do internally is a SHA-256 hash of the username, and we use that to set ranges and parameters that we use in conjunction with a standard, time based random so while the actions/timings are within a unique range per account but you're not getting the exact same result each time you run a script.

    To your question about getting a number within a set range, you can use the modulo operator, it returns the remainder of division:

    int randomNumber = 2009;
    int numberLessThan20 = randomNumber % 20; // The remainder of 2009 / 20, which is 9 in this case

     

    Link to comment
    Share on other sites

    7 minutes ago, Pandemic said:

    You have to be really careful when generating random numbers, especially when using the same seed. You will always get the same "random" numbers in the exact same order every time you run something, which actually makes this example extremely detectable from a pattern detection perspective.

    What we do internally is a SHA-256 hash of the username, and we use that to set ranges and parameters that we use in conjunction with a standard, time based random so while the actions/timings are within a unique range per account but you're not getting the exact same result each time you run a script.

    To your question about getting a number within a set range, you can use the modulo operator, it returns the remainder of division:

    int randomNumber = 2009;
    int numberLessThan20 = randomNumber % 20; // The remainder of 2009 / 20, which is 9 in this case

     

    But humans aren't truly random, so wouldn't it make sense to keep a similar characteristic across bots?

    Link to comment
    Share on other sites

    2 minutes ago, notsmile said:

    But humans aren't truly random, so wouldn't it make sense to keep a similar characteristic across bots?

    Yeah, that's why we set certain parameters and standard ranges per user and use that to help the normal time based random.

    If you use the "random" number you have up above, every time you use a Random with that same seed, you'll get the same outputs like this:

    // First script run
    
    sleep(random.nextInt(1000)); // 443
    // Do something else
    Mouse.move(random.nextInt(400), random.nextInt(300)); // 101, 201
    
    // Stop and re-run the script
    
    sleep(random.nextInt(1000)); // 443
    // Do something else
    Mouse.move(random.nextInt(400), random.nextInt(300)); // 101, 201
    
    // Forever

     

    Link to comment
    Share on other sites

    Just now, Pandemic said:

    Yeah, that's why we set certain parameters and standard ranges per user and use that to help the normal time based random.

    If you use the "random" number you have up above, every time you use a Random with that same seed, you'll get the same outputs like this:

    // First script run
    
    sleep(random.nextInt(1000)); // 443
    // Do something else
    Mouse.move(random.nextInt(400), random.nextInt(300)); // 101, 201
    
    // Stop and re-run the script
    
    sleep(random.nextInt(1000)); // 443
    // Do something else
    Mouse.move(random.nextInt(400), random.nextInt(300)); // 101, 201
    
    // Forever

     

    Ah ok, that makes sense then. Hopefully I'll be able to improve on it! :) 

    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
     Share

    ×
    ×
    • 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.