In this code I create first a list with some names and then print them randomly:
This code prints only one name everytime I run it. Now if I want to have for exemple 3 random names from that list each time, how should I modify my code ?!
I tried with this but failed:
package testrandom; public class TestRandom { public static void main(String[] args) { String [] name={"Bob","Joe","Max","Alfred","Mat"}; int min =0; int max= name.length; for (int i=0; i<4;i++) ///System.out.println("Random value in int from " +min+"to "+max+" : "); int random_int = (int)Math.floor(Math.random()*(max-min+1)+min); //System.out.println(random_int); System.out.println(name[random_int]); } }