modified measureStabilityRand to handle continuous X, with optional nonnegativity constraint.