0

I have a list of 14 items that I use in method. I was wondering how I can make randomly pick different items from the list instead of forcing selecting by list number [0] etc. The code in the method is like this.

stats.list[0].clone (); 

I need to it be something like..

stats.list[RANDOMNUMBER/DECISION].clone (); 

My list code is like

 list [0] = new Ped (names.getString("idc"), "C"); list [1] = new Ped (names.getString("id"), "D"); 

Thanks for ya help!

2
  • 3
    err, lookup random in java: docs.oracle.com/javase/7/docs/api/java/util/Random.html Commented Mar 13, 2013 at 6:53
  • yeh I did, just not sure how to implement it. Isn't this why stackoverflow is made for? Specific programming problems :) Commented Mar 13, 2013 at 7:03

1 Answer 1

3
Random r = new Random(); int randomNum = r.nextInt(sizeOfList); stats.list[randomNum].clone (); 

Use the random class.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.