int n = (int) Math.round(size * nonZeroFraction);
if (n == 0) {
return matrix;
}
RandomSamplingAssistant sampler =
new RandomSamplingAssistant(n, size, RandomUtils.getRandom());
for (int i = 0; i < size; i++) {
if (sampler.sampleNextElement()) {
int row = i / columns;
int column = i % columns;
matrix.set(row, column, value);
}
}