Rolled Gold Posted September 13, 2016 Share Posted September 13, 2016 Noob here still working on my first few scripts. Wondering the best way to choose a random action. for example, choosing between using a bank deposit box and the bank function. Right now i have it written as such: if(inventory.isFull() && random(100,200)%2 == 0 ){ return State.DEPOSITBOX; else return State.BANK; } is this a good practice? (using more actions and mods?) I've seen some talk about using https://en.wikipedia.org/wiki/Random_seed .. if that's the way to do it would someone mind providing an example (using a timer?) I imagine you don't want your bot to uniformly distribute the "random" options over time.. Appreciate any input. Quote Link to comment Share on other sites More sharing options...
Team Cape Posted September 13, 2016 Share Posted September 13, 2016 that code will aggressively switch between states and make you go back and forth between the deposit box state and the bank state Quote Link to comment Share on other sites More sharing options...
Rolled Gold Posted September 13, 2016 Author Share Posted September 13, 2016 that code will aggressively switch between states and make you go back and forth between the deposit box state and the bank state Sorry wasn't using my actual script. Just trying to get the general idea across.. using a mod to determine the action? Quote Link to comment Share on other sites More sharing options...
Trees Posted September 13, 2016 Share Posted September 13, 2016 (edited) You don't have to worry about using a seed if you use: import java.util.concurrent.ThreadLocalRandom; ThreadLocalRandom.current().nextInt(min, max + 1); And the way you set up the modulus it does give a 50% chance. You can also try a % chance by doing something like if(random(0, 101) <= 75)) [psuedocode] for 75% (or 76% I forget if it's inclusive or not, xD) chance for example. One thing to note if you do it this way is you only want to generate the random number once. Otherwise you have a potentially different chance for each task. Edited September 13, 2016 by Trees 1 Quote Link to comment Share on other sites More sharing options...
FrostBug Posted September 13, 2016 Share Posted September 13, 2016 (edited) You don't have to worry about using a seed if you use: import java.util.concurrent.ThreadLocalRandom; ThreadLocalRandom.current().nextInt(min, max + 1); And the way you set up the modulus it does give a 50% chance. You can also try a % chance by doing something like if(random(0, 101) <= 75)) [psuedocode] for 75% (or 76% I forget if it's inclusive or not, xD) chance for example. One thing to note if you do it this way is you only want to generate the random number once. Otherwise you have a potentially different chance for each task. Why would you worry about using a seed for this in the first place Can agree that random(100, 200) % 2 seems a bit silly tho; might aswell go for random(2) == 0 Edited September 13, 2016 by FrostBug Quote Link to comment Share on other sites More sharing options...
Prolax Posted September 13, 2016 Share Posted September 13, 2016 Why would you worry about using a seed for this in the first place Can agree that random(100, 200) % 2 seems a bit silly tho; might aswell go for random(2) == 0 Indeed, why would you use a mod for that. Quote Link to comment Share on other sites More sharing options...
Alek Posted September 13, 2016 Share Posted September 13, 2016 Looks like you're trying to use a 50/50 chance, don't over complicate it with useless calculations. Also check your brackets, looks like you're giving it an entirely different meaning. As far as making something "random", you can always figure out the bounds by gathering enough input. Still, better of an attempt than simply moving your mouse/camera around randomly. Quote Link to comment Share on other sites More sharing options...
Trees Posted September 13, 2016 Share Posted September 13, 2016 Indeed, why would you use a mod for that. In terms of randomness, it makes the distribution larger. Of course it'd be more useful if you were using a value other than 2, but still. And as far as a seed goes it's probably not needed for this anyways. Quote Link to comment Share on other sites More sharing options...