public static Collection < OrderedPair > sampleOrderedPairs ( int minI , int maxI , int minJ , int maxJ , double prop ) { int numI = maxI - minI ; int numJ = maxJ - minJ ; // Count the max number possible: long maxPairs = numI * numJ ; Collection < OrderedPair > samples ; if ( maxPairs < 400000000 || prop > 0.1 ) { samples = new ArrayList < OrderedPair > ( ) ; for ( int i = minI ; i < maxI ; i ++ ) { for ( int j = minJ ; j < maxJ ; j ++ ) { if ( prop >= 1.0 || Prng . nextDouble ( ) < prop ) { samples . add ( new OrderedPair ( i , j ) ) ; } } } } else { samples = new HashSet < OrderedPair > ( ) ; double numSamples = maxPairs * prop ; while ( samples . size ( ) < numSamples ) { int i = Prng . nextInt ( numI ) + minI ; int j = Prng . nextInt ( numJ ) + minJ ; samples . add ( new OrderedPair ( i , j ) ) ; } } return samples ; }
Sample with replacement ordered pairs of integers .