Random Item From Array

Discussion in 'Plugin Development' started by Azrex, May 14, 2015.

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

    Azrex

    So is it possible that I make an array of Itemstacks and get a random item from it and place it in an inventory?
    If so, how?
     
  2. Offline

    DaanSander

    make a random number and use <ArrayName>.get(number);
     
  3. Offline

    1Rogue

  4. Offline

    Azrex

    So how do I use this code?
     
  5. Offline

    caderape

    @Azrex Show of your code. I don't really get how your array is set.
     
  6. Offline

    Zombie_Striker

    Code:
    ItemStack[new Random().nextInt(ItemStack.Size+1)];;
    
    // or
    
    ArrayListofItemStacks.get(new Random().nextInt(ALOIS.size+1));;
     
  7. Offline

    1Rogue

    You should definitely not instantiate new randoms each time, using ThreadLocalRandom is best for that use-case.
     
  8. Offline

    Zombie_Striker

    Or just crate once instance of Random() for your whole plugin, and reference that when getting a new randomInt.
     
  9. Offline

    1Rogue

    Which honestly is still more work than just using ThreadLocalRandom
     
    teej107 likes this.
Thread Status:
Not open for further replies.

Share This Page