Jump to content

Picking A Random Action


Rolled Gold

Recommended Posts

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. 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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