• Are you not able to open the client? Try following our getting started guide
• Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
• How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
• # Randomly choose between two ints

## Recommended Posts

How would i get it to randomly choose between two integers? For example, i want it to randomly to choose between either 3 or 5.

##### Share on other sites

8 minutes ago, Shy said:

i dont want to choose between the two numbers, i want it to choose only from the set of two numbers.

##### Share on other sites

5 hours ago, Wayslili said:

i dont want to choose between the two numbers, i want it to choose only from the set of two numbers.

2 ways:

1) Through an array using the Random class.

```Random random = new Random();

int randomPickedNumber = arrayName(random.nextInt(arrayName));```

2) Through Lists using Collections.shuffle();

```ArrayList<Integer> listName = new ArrayList<Integer>();

Collections.shuffle(listName);

int randomPickedNumber = listName.get(0);```

You can also turn the array into a list using

`Collections.asList(arrayName); `

or turn the list into an array using

`Arrays.toArray(listName);`

Also there's a way to pick between 2 numbers is by chance, like the following:

```int chance = Calculations.random(1,100);

int chosenNumber;

if(chance <=50) chosenNumber = firstInteger;

else chosenNumber = secondInteger;```

hope this helps

##### Share on other sites

1 hour ago, Infidel said:

Nice example @Defiled

ty ❤

##### Share on other sites

10 hours ago, Wayslili said:

i dont want to choose between the two numbers, i want it to choose only from the set of two numbers.

Sorry, I misunderstood. Defiled has provided some good examples, but to add an additional one. If you only want to have two selection choices:

```private Random random = new Random();

int randomOfTwoNumbers = random.nextBoolean() ? 3 : 5); // replace 3 and 5 with the numbers you want ```