Wayslili 0 Share Posted March 12, 2020 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. Link to comment Share on other sites More sharing options...
Shy 14 Share Posted March 12, 2020 https://dreambot.org/javadocs/org/dreambot/api/methods/Calculations.html#random-int-int- Link to comment Share on other sites More sharing options...
Wayslili 0 Author Share Posted March 12, 2020 8 minutes ago, Shy said: https://dreambot.org/javadocs/org/dreambot/api/methods/Calculations.html#random-int-int- i dont want to choose between the two numbers, i want it to choose only from the set of two numbers. Link to comment Share on other sites More sharing options...
Defiled 415 Share Posted March 12, 2020 (edited) 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 Edited March 12, 2020 by Defiled Zawy, BrownK1d and Semper Fi 2 1 Link to comment Share on other sites More sharing options...
Defiled 415 Share Posted March 12, 2020 1 hour ago, Infidel said: Nice example @Defiled ty ❤ Link to comment Share on other sites More sharing options...
Shy 14 Share Posted March 12, 2020 (edited) 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 Edited March 12, 2020 by Shy Typo Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now