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
  • Random Constants


    Recommended Posts

    The purpose of this is to allow you to have temporal control over RNG without saving data between sessions. For example if you want to randomize the loop speed of a script between 2 numbers and you want variance between people this would be perfect, or if you want a configuration setting to be random for the users of your script you can use this.


    package random;
    import java.io.UnsupportedEncodingException;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
     * Created by Dorkinator on 6/17/2017.
    public class RandomConstant {
    	private String seed;
    	private String constant;
    	private long duration = 0;
    	private int min;
    	private int max;
    	public RandomConstant(String seed, String constant, int min, int max){
    		this.seed = seed;
    		this.constant = constant;
    		this.min = min;
    		this.max = max;
    	public RandomConstant(String seed, String constant, int min, int max, long duration){
    		this.seed = seed;
    		this.constant = constant;
    		this.min = min;
    		this.max = max;
    		this.duration = duration;
    	private long timeOffset(){
    		return (long)(nextDouble(seed+constant+min+max+(System.currentTimeMillis()/duration))*duration);
    	private double nextDouble(String input){
    		String hash = hash(input);
    		final int ln = 6;
    		final double max = Math.pow(16,ln);
    		return ((double)Integer.parseInt(hash.substring(hash.length()-ln,hash.length()), 16))/max;
    	private double nextDouble(){
    		return nextDouble(seed + constant + min + max + ((System.currentTimeMillis()+timeOffset()) / duration));
    	public int get(){
    		return (int)((nextDouble()*(double)(max-min))+(double)min);
    	private static String hash(String input){
    		MessageDigest md;
    		try {
    			md = MessageDigest.getInstance("SHA-512");
    			md.update((input).toString().getBytes("UTF-8")); // Change this to "UTF-16" if needed
    			byte[] digest = md.digest();
    			return String.format("%064x", new java.math.BigInteger(1, digest));
    		} catch (NoSuchAlgorithmException e) {
    		} catch (UnsupportedEncodingException e) {
    		return null;
    Link to comment
    Share on other sites


    This topic is now archived and is closed to further replies.

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