private List < INodeEntry > select ( final int count , final Collection < INodeEntry > nodes ) { List < INodeEntry > source = new ArrayList <> ( nodes ) ; List < INodeEntry > selected = new ArrayList <> ( ) ; int total = Math . min ( count , nodes . size ( ) ) ; for ( int i = 0 ; i < total ; i ++ ) { selected . add ( source . remove ( random . nextInt ( source . size ( ) ) ) ) ; } return selected ; }
Select count random items from the input nodes or if nodes is smaller than count reorders them