Question

There are 5 people and 5 things. 5 people are

Mg Mg, Su Su, Zaw Zaw, Kyaw Kyaw, Mya Mya

5 things are

Iphone, mp3, tv and two thank you

I want each person to get a thing randomly like lucky draw every time I run this in Java. I can't get the same people to get the same thing if I run the second time. I am not sure if I can use the array method for names or things to store them.

Can you tell me how to do that? Can I get the code if possible?

I've already tried this but have no idea how to continue.

ArrayList<String> name = new ArrayList<String>();
name.add("Mg Mg");
name.add("Su Su");
name.add("Zaw Zaw");
name.add("Kyaw Kyaw");
name.add("Mya Mya");
Was it helpful?

Solution

 ArrayList<String> name = new ArrayList<String>();
    name.add("Mg Mg");
    name.add("Su Su");
    name.add("Zaw Zaw");
    name.add("Kyaw Kyaw");
    name.add("Mya Mya");

    ArrayList<String> items = new ArrayList<String>();
    items.add("Iphone");
    items.add("mp3");
    items.add("tv ");
    items.add("Iphone4");
    items.add("Iphone5");

    int rand = (int) (Math.random() * 5);

Every time you have to generate Random number, you have to save rand number into DB/file. And check that new generated no is in file or not. If it is not there then use that number for mapping and it is there then generate again the number.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top