Here you can find the source of chooseRandomThing(Collection> possibleroutes)
Parameter | Description |
---|---|
possiblerebroutes | a parameter |
public static Object chooseRandomThing(Collection<?> possibleroutes)
//package com.java2s; //License from project: Open Source License import java.util.Collection; import java.util.Random; public class Main { /**// www. j av a2 s. com * Function chooseRandomPath * -------------------------- * This function takes in a set of possible routes and simply * chooses a random element from the list. * @param possiblerebroutes * @return */ public static Object chooseRandomThing(Collection<?> possibleroutes) { if (possibleroutes == null) { return null; } int size = possibleroutes.size(); int item = new Random().nextInt(size); int i = 0; for (Object p : possibleroutes) { if (i == item) return p; i++; } // shouldn't reach here return null; } }