digdig18 Posted April 3, 2014 Share Posted April 3, 2014 I can't get it work, building a method for getting random coords Positions, but it never works, all help will be aprecciate import java.util.ArrayList; import java.util.Random; import org.osbot.script.rs2.map.Position; public class testa { public static void main(String[] args) { // TODO Auto-generated method stub ArrayList<Position> tree = new ArrayList<>(); tree.add(new Position(2827,3087,0)); tree.add(new Position(2827,3036,0)); tree.add(new Position(2826,3087,0)); tree.add(new Position(2826,3085,0)); for(int i = 0; i < tree.size(); i++){ Random r = new Random(); i = r.nextInt(i); tree.get(i); System.out.println(i); } } } Link to comment Share on other sites More sharing options...
Joseph Posted April 3, 2014 Share Posted April 3, 2014 (edited) What does it log? Edit: please start getting use to using a list. List<Position> tree = new ArrayList<Position>(); Edited April 3, 2014 by josedpay Link to comment Share on other sites More sharing options...
thelegacy0 Posted April 3, 2014 Share Posted April 3, 2014 System.out.println(i); Should just print out 1-4 (0-3?)... I'm not all to familiar with Position, but look at this - String[] Salutations = {"Hi", "Hello", "Hey"}; public void onMyCommand() { Random r = newRandom(); int pickMe = r.random(Salutations.size()-1); //Whatever the random integer method is, ranging from 0 to 1 less than the max array value //Arrays start at 0 System.out.println(Salutations[pickMe]+" there, digdig18."); } You take a random number, that wouldn't exceed the value of your array, and then select that position in the array. Link to comment Share on other sites More sharing options...
Ande Posted April 3, 2014 Share Posted April 3, 2014 (edited) I would probably do it like this public final Position[] positions = {new Position(2827,3087,0), new Position(2827,3036,0), new Position(2826,3087,0), new Position(2826,3085,0)}; public Position getRandomPosition(){ return positions[random(positions.length)]; } Edited April 3, 2014 by Ande 2 Link to comment Share on other sites More sharing options...
digdig18 Posted April 4, 2014 Author Share Posted April 4, 2014 On 4/3/2014 at 4:17 AM, thelegacy0 said: System.out.println(i); Should just print out 1-4 (0-3?)... I'm not all to familiar with Position, but look at this - String[] Salutations = {"Hi", "Hello", "Hey"}; public void onMyCommand() { Random r = newRandom(); int pickMe = r.random(Salutations.size()-1); //Whatever the random integer method is, ranging from 0 to 1 less than the max array value //Arrays start at 0 System.out.println(Salutations[pickMe]+" there, digdig18."); } You take a random number, that wouldn't exceed the value of your array, and then select that position in the array. Yes mr thelegacy0, it should pick a random number between 1-4 (i have 4 coords), and thank's ! On 4/3/2014 at 11:02 AM, Ande said: I would probably do it like this public final Position[] positions = {new Position(2827,3087,0), new Position(2827,3036,0), new Position(2826,3087,0), new Position(2826,3085,0)}; public Position getRandomPosition(){ return positions[random(positions.length)]; } I'm surprised with your lean code, probably i will use this, thanks for the attention. Link to comment Share on other sites More sharing options...
thelegacy0 Posted April 4, 2014 Share Posted April 4, 2014 I meant System.out.println(i) literally prints out "1", "2", "3", or "4" Link to comment Share on other sites More sharing options...