public static FlatDataCollection randomSampling ( FlatDataList idList , int n , boolean randomizeRecords ) { FlatDataList sampledIds = new FlatDataList ( ) ; int populationN = idList . size ( ) ; Object [ ] keys = idList . toArray ( ) ; if ( randomizeRecords ) { PHPMethods . < Object > shuffle ( keys ) ; } int k = populationN / n ; //number of systematics if ( k < 2 ) { throw new IllegalArgumentException ( "The number of systematics is too small." ) ; } int randomSystematic = PHPMethods . mt_rand ( 0 , k - 1 ) ; for ( int i = randomSystematic ; i < keys . length ; i += k ) { Object pointID = keys [ i ] ; sampledIds . add ( pointID ) ; } return sampledIds . toFlatDataCollection ( ) ; }
Samples n ids by using Systematic Sampling