private static double absDiffOfMeans ( double [ ] A , double [ ] B , boolean randomize ) { Random random = new Random ( ) ; double aTotal = 0.0 ; double bTotal = 0.0 ; for ( int i = 0 ; i < A . length ; i ++ ) { if ( randomize && random . nextBoolean ( ) ) { aTotal += B [ i ] ; bTotal += A [ i ] ; } else { aTotal += A [ i ] ; bTotal += B [ i ] ; } } double aMean = aTotal / A . length ; double bMean = bTotal / B . length ; return Math . abs ( aMean - bMean ) ; }
Assumes input arrays have equal non - zero length .