I want to create a random number to apply to some arrays in order to get different elements in each execution. Arrays contain the names of sports products (product, size, price, etc.). By doing this, I want to make random products that fall into the string, but every time I run the program I get the same product.
Where is the problem?
Here is the code in the generaProductos class:
public void generaProductos() { int num; for (int i=0;i<3;i++){ num = (int) Math.random() * 3; String cliente = tipoProducto[num] + " " + deporte[num] + " " + destinatario[num] + " " + color[num] + " " + tallaRopaAdulto[num] + " " + preciosIVA[num]; System.out.println(cliente); } return; }
And here I call the generaProductos() method basically:
switch (opt){ case 1: generaProductos alm = new generaProductos(); alm.generaProductos();
When I execute my code, I always get the following:
Botas Futbol Hombre Marron S 16.99
Botas Futbol Hombre Marron S 16.99
Botas Futbol Hombre Marron S 16.99
(In English it would be football boots with brown sizes S 16.99)
source share