hello everybody,
this is my first post, although i have read this forum in the past.
i have a slight problem with a random number generator that im sure is simple to fix.
my program has 1 button and 3 text boxes. when i click the button, a random number between 1 and 5 should appear in each of the three boxes. Every time i press the button, a random number does appear in each box, but it is the same number. ie. 1 1 1 or 4 4 4. what is wrong with my code that prevents 3 random numbers being generated, as i do not want to generate a random number and repeat it three times!
here is my code.
String food;
Random f = new Random();
int randFood = (Math.abs(f.nextInt()) % 5) + 1;
food=String.valueOf(randFood);
jTextField1.setText(food);
String wood;
Random w = new Random();
int randWood = (Math.abs(w.nextInt()) % 5) + 1;
wood=String.valueOf(randWood);
jTextField2.setText(wood);
String Ore;
Random o = new Random();
int randOre = (Math.abs(o.nextInt()) % 5) + 1;
Ore=String.valueOf(randOre);
jTextField3.setText(Ore);
thankyou in advance,
joseph :-)