Solved Getting random locations

Discussion in 'Spigot Plugin Development' started by pas5w0rd, Apr 29, 2017.

Thread Status:
Not open for further replies.
  1. Hey y'all!

    Does anyone know how I could go about getting random locations from a config. So.
    I have my:

    Code (Text):
      for(String locations : filez.getConfigurationSection("Drop").getKeys(false))
             {
    but I don't know how to simply randomly select them and broadcast them in chat.
    I know how to get them, but each time a want like 15 random locations (there is 30 in total).

    Any ideas?
    Thanks.
     
  2. I'm not sure if this is the best way to do it, but it works:
    Put them in a list. Generate a random number and get the Location associated with that index from the list and remove that element from the list (with this method). Repeat this as many times as many random locations you need, but make sure there are enough in the config and you specify the right bounds for the RNG every time.
     
    • Agree Agree x 1
  3. So- the ones left in the list are the ones that I then use?
     
  4. You either have to store the removed elements and repeat the task as many times as many random locations you want
    OR
    you remove random elements from the list until there are only as many left as many random locations you need.

    I believe the first method is the better one.
     
  5. Thanks, it worked!
     
Thread Status:
Not open for further replies.