Jump to content

Picking A Random Action


Recommended Posts

Posted

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. 

Posted (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 by Trees
  • Like 1
Posted (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 boge.png

 

Can agree that random(100, 200) % 2 seems a bit silly tho; might aswell go for random(2) == 0

 

Edited by FrostBug
Posted

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. 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...