September 13, 20169 yr 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.
September 13, 20169 yr that code will aggressively switch between states and make you go back and forth between the deposit box state and the bank state
September 13, 20169 yr Author 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?
September 13, 20169 yr 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, 20169 yr by Trees
September 13, 20169 yr 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, 20169 yr by FrostBug
September 13, 20169 yr 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.
September 13, 20169 yr 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.
September 13, 20169 yr 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.
Create an account or sign in to comment