Simple random help

Discussion in 'Plugin Development' started by CactusComboPvP, Aug 22, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    CactusComboPvP

    Hey everyone, hope you're having a nice day.
    So, i have got somewhat a problem.

    I coded something which adds certain items to an inventory.
    I made a random to add random items, but one thing.

    It is supposed to have different items in each of the different chests, and just more than one item.

    But when I run the command, it simply only adds one item to the chests and it is the same item in all the chests.

    Code so far:

    Code:java
    1. Random random = new Random();
    2. List<Material> randomItems = Arrays.asList(Material.AIR, Material.IRON_CHESTPLATE, Material.APPLE, Material.ARROW, Material.IRON_SWORD);
    3. Material randomItem = randomItems.get(random.nextInt(randomItems.size()));
    4. inv1.addItem(new ItemStack(randomItem));
    5. inv2.addItem(new ItemStack(randomItem));
    6. inv3.addItem(new ItemStack(randomItem));
    7. inv4.addItem(new ItemStack(randomItem));


    Again, what I want it to do is add more than 1 random items (different in each chest) to each of the inventory.
     
  2. Offline

    Gater12

    CactusComboPvP

    Get a random index each time when you add an item.
     
  3. Offline

    CactusComboPvP

    Gater12
    Can you explain in more detail please?
     
  4. Offline

    Gater12

    CactusComboPvP

    Get an element at a random index every time you add an item.
     
  5. Offline

    CactusComboPvP

    Gater12
    I know this sounds like I'm trying to be spoon fed, but could you please give me some example?
     
  6. Offline

    Gater12

    CactusComboPvP
    Code:
    inv1.addItem(list.get(a new random int));
    inv2.addItem(list.get(another new random int));
    //And so on
     
  7. Offline

    CactusComboPvP

    Gater12
    inv1.addItem(new ItemStack(randomItems.get(5)));
    inv2.addItem(new ItemStack(randomItems.get(2)));

    I done that but now nothing is in the chests
     
  8. Offline

    Gater12

    CactusComboPvP
    I mean every time you add an item you get a new random number.

    Code:java
    1. inv1.addItem(randomGen.nextInt(list.size()));
     
Thread Status:
Not open for further replies.

Share This Page