Kati2 Posted July 29, 2013 Share Posted July 29, 2013 I became annoyed at typing sleep x + gRandom(y,z); so I wrote this so you can simply enter three values (you can change it to more) and it will randomize the sleep method furthermore. Not only that, instead of having to type out your sleep every time, you just type: Sleep(); Here's the code: private boolean dynamicBase; int s0 = 750; // Base value int s1 = 0; double s2 = 0; public void subSleep() throws InterruptedException { sleep(s0 + gRandom(s1, s2)); } public void sleep() throws InterruptedException { Random sleepRandom = new Random(); switch (random(1, 3)) { case 1: if (dynamicBase) { s0 = sleepRandom.nextInt(500); } s1 = sleepRandom.nextInt(1000); s2 = 250 + (1500 - 500) * sleepRandom.nextDouble(); subSleep(); case 2: if (dynamicBase) { s0 = sleepRandom.nextInt(100); } s1 = sleepRandom.nextInt(250); s2 = 500 + (800 - 200) * sleepRandom.nextDouble(); subSleep(); case 3: if (dynamicBase) { s0 = sleepRandom.nextInt(45); } s1 = sleepRandom.nextInt(250); s2 = 500 + (800 - 200) * sleepRandom.nextDouble(); subSleep(); } } Pretty much, your sleep is now: randomBase(optionally) + randomint(randomint + (randomint(randomint)) + (randomDouble(randomDouble))) Making your sleeps math-ambiguous. 2 Link to comment Share on other sites More sharing options...
GoldenGates Posted July 29, 2013 Share Posted July 29, 2013 Thank you, I actually used that method, cba to add fully dynamic sleeps. Link to comment Share on other sites More sharing options...
Brainfree Posted July 29, 2013 Share Posted July 29, 2013 Layered randomcy. 2 Link to comment Share on other sites More sharing options...
Laz Posted July 29, 2013 Share Posted July 29, 2013 l2 use conventions :P 1 Link to comment Share on other sites More sharing options...
GoldenGates Posted July 29, 2013 Share Posted July 29, 2013 l2 use conventions lol @"S"leep Link to comment Share on other sites More sharing options...
Joseph Posted July 29, 2013 Share Posted July 29, 2013 So how would you use this. Sleep(500+200,300); Link to comment Share on other sites More sharing options...
Kati2 Posted July 29, 2013 Author Share Posted July 29, 2013 l2 use conventions Happy? :P So how would you use this. Sleep(500+200,300); If you want to do that just use the normal method.. Link to comment Share on other sites More sharing options...
GoldenGates Posted July 29, 2013 Share Posted July 29, 2013 l2 use conventions Happy? So how would you use this. Sleep(500+200,300); If you want to do that just use the normal method.. No, you missed a spot. @1st Sleep(); Link to comment Share on other sites More sharing options...
Dreamliner Posted July 29, 2013 Share Posted July 29, 2013 (edited) I think you would be much better off using this (quick writeup) public void newSleep(int min, int max) { int x = 0; do { x = gRandom(min,max,(double)(max-min)/2); } while (x < min || x > max); sleep(x); } This way you can refine it in certain areas of your code, instead of it being generally around one area. Edited July 29, 2013 by dreamliner Link to comment Share on other sites More sharing options...
Cory Posted July 30, 2013 Share Posted July 30, 2013 Nice, would use but I don't use sleeps. Link to comment Share on other sites More sharing options...
Boots Posted July 30, 2013 Share Posted July 30, 2013 l2 use conventions Happy? So how would you use this. Sleep(500+200,300); If you want to do that just use the normal method.. why not use dynamic sleeps? import timer.Timer; import org.osbot.script.Script; import org.osbot.script.rs2.model.Player; public class Singleton { private final Script script; private static Singleton oneInstance; private Singleton(Script script){ this.script = script; } public static Singleton getInstance(final Script script){ if(oneInstance == null){ oneInstance = new Singleton(script); } return oneInstance; } public boolean isIdle(){ Player p = script.client.getMyPlayer(); return !p.isAnimating() && p.getAnimation()==-1 && !p.isMoving() && !p.isUnderAttack(); } public void dynamicSleep(final boolean condition){ Timer timer = new Timer(800); try{ while(!isIdle() && condition && timer.isRunning()) script.sleep(10); } catch (InterruptedException e){e.printStackTrace();} } } Link to comment Share on other sites More sharing options...
Kati2 Posted July 30, 2013 Author Share Posted July 30, 2013 I think you would be much better off using this (quick writeup) public void newSleep(int min, int max) { int x = 0; do { x = gRandom(min,max,(double)(max-min)/2); } while (x < min || x > max); sleep(x); } This way you can refine it in certain areas of your code, instead of it being generally around one area. That's not as randomized as the method I posted, nor is it as simplified. l2 use conventions Happy? So how would you use this. Sleep(500+200,300); If you want to do that just use the normal method.. why not use dynamic sleeps? import timer.Timer; import org.osbot.script.Script; import org.osbot.script.rs2.model.Player; public class Singleton { private final Script script; private static Singleton oneInstance; private Singleton(Script script){ this.script = script; } public static Singleton getInstance(final Script script){ if(oneInstance == null){ oneInstance = new Singleton(script); } return oneInstance; } public boolean isIdle(){ Player p = script.client.getMyPlayer(); return !p.isAnimating() && p.getAnimation()==-1 && !p.isMoving() && !p.isUnderAttack(); } public void dynamicSleep(final boolean condition){ Timer timer = new Timer(800); try{ while(!isIdle() && condition && timer.isRunning()) script.sleep(10); } catch (InterruptedException e){e.printStackTrace();} } } As I said, I was trying to make it as random as possible. Link to comment Share on other sites More sharing options...
Herbz Posted July 30, 2013 Share Posted July 30, 2013 I became annoyed at typing sleep x + gRandom(y,z); so I wrote this so you can simply enter three values (you can change it to more) and it will randomize the sleep method furthermore. Not only that, instead of having to type out your sleep every time, you just type: Sleep(); Here's the code: private boolean dynamicBase; int s0 = 750; // Base value int s1 = 0; double s2 = 0; public void subSleep() throws InterruptedException { sleep(s0 + gRandom(s1, s2)); } public void sleep() throws InterruptedException { Random sleepRandom = new Random(); switch (random(1, 3)) { case 1: if (dynamicBase) { s0 = sleepRandom.nextInt(500); } s1 = sleepRandom.nextInt(1000); s2 = 250 + (1500 - 500) * sleepRandom.nextDouble(); subSleep(); case 2: if (dynamicBase) { s0 = sleepRandom.nextInt(100); } s1 = sleepRandom.nextInt(250); s2 = 500 + (800 - 200) * sleepRandom.nextDouble(); subSleep(); case 3: if (dynamicBase) { s0 = sleepRandom.nextInt(45); } s1 = sleepRandom.nextInt(250); s2 = 500 + (800 - 200) * sleepRandom.nextDouble(); subSleep(); } } Pretty much, your sleep is now: randomBase(optionally) + randomint(randomint + (randomint(randomint)) + (randomDouble(randomDouble))) Making your sleeps math-ambiguous. Kati! Finally Yay A Snippet Thanks! I Will Be Using This! Link to comment Share on other sites More sharing options...
Illumi Posted July 30, 2013 Share Posted July 30, 2013 What's wrong with sleep(random(min, max)); Why make something simple, complicated? -,- Link to comment Share on other sites More sharing options...
Dreamliner Posted July 30, 2013 Share Posted July 30, 2013 (edited) I think you would be much better off using this (quick writeup) public void newSleep(int min, int max) { int x = 0; do { x = gRandom(min,max,(double)(max-min)/2); } while (x < min || x > max); sleep(x); } This way you can refine it in certain areas of your code, instead of it being generally around one area. That's not as randomized as the method I posted, nor is it as simplified. I'd have to disagree. I did a little bit of statistical analysis on your method: Case one yields an average range of 750 to 2000 if not using a dynamic base. Case one yields an average range of 250 to 1500 if using a dynamic base. Case two yields an average range of 750 to 1675 if not using a dynamic base. Case two yields an average range of 50 to 975 if using a dynamic base. Case three yields an average range of 750 to 1675 if not using a dynamic base. Case three yields an average range of 23 to 948 if using a dynamic base. (all of these are bell curves with their peak at the mean) If you logged every time the bot slept, you would have a graph that looks like 2 or 3 superimposed bell curves (or 5 if you randomly use the dynamic base). To have something truly random, you have to use this method along with a way of changing the base to better suit your needs in a script. Such as an action that requires 1 tick compared to something that needs 5. If you slept the same way every time, it would look obvious by the randomness of it. By default, humans are not random. There was a study done that asked a human to flick on and off a light switch in a random pattern. The study concluded that there was a non-random pattern that the person followed subconsciously. When humans do actions, they get tuned to what they are doing. It is very easy to keep the beat in a song, compared to trying to play something in random intervals. Its not how our brains work. This is a very well written video explaining what I'm walking about http://www.youtube.com/watch?v=H2lJLXS3AYM Edited July 30, 2013 by dreamliner Link to comment Share on other sites More sharing options...