OK, so I'm fairly new to Java programming and I'm experiencing a problem with randomly generating a result from a String array.
I've got an applet I'm working on which will have a JButton and a JTextArea. The JButton will generate a few things in the JTextArea each time it is pressed and one of the things I'd like it to generate is a random text from my String array. It works just fine the first time the button is pressed...in that it generates a random result from the array, but when the button is pressed another time it will display the first random result again instead of a new random result.
I've got a similar method of generating random numbers that works just fine, it's just for some reason when I use the String array it does this. Am I just missing something?
Here is the code for the random String array generation:
CODE
import java.util.Random;
public class stringList {
String[] sList = { "item 1", "item 2", "item 3", "item 4"};
Random s = new Random();
int Select = 0;
String list = sList[produceNumber()];
public int produceNumber()
{
Select = (s.nextInt(sList.length));
return Select;
}
}