static DBIDs randomSample ( DBIDs ids , int samplesize , Random rnd , DBIDs previous ) { if ( previous == null ) { return DBIDUtil . randomSample ( ids , samplesize , rnd ) ; } ModifiableDBIDs sample = DBIDUtil . newHashSet ( samplesize ) ; sample . addDBIDs ( previous ) ; sample . addDBIDs ( DBIDUtil . randomSample ( ids , samplesize - previous . size ( ) , rnd ) ) ; // If these two were not disjoint, we can be short of the desired size! if ( sample . size ( ) < samplesize ) { // Draw a large enough sample to make sure to be able to fill it now. // This can be less random though, because the iterator may impose an // order; but this is a rare code path. for ( DBIDIter it = DBIDUtil . randomSample ( ids , samplesize , rnd ) . iter ( ) ; sample . size ( ) < samplesize && it . valid ( ) ; it . advance ( ) ) { sample . add ( it ) ; } } return sample ; }
Draw a random sample of the desired size .