in commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/MarsagliaTsangWangDiscreteSampler.java [384:402]
public int sample() {
final int j = rng.nextInt() >>> 2;
if (j < t1) {
return table1[j >>> 24] & MASK;
}
if (j < t2) {
return table2[(j - t1) >>> 18] & MASK;
}
if (j < t3) {
return table3[(j - t2) >>> 12] & MASK;
}
if (j < t4) {
return table4[(j - t3) >>> 6] & MASK;
}
// Note the tables are filled on the assumption that the sum of the probabilities.
// is >=2^30. If this is not true then the final table table5 will be smaller by the
// difference. So the tables *must* be constructed correctly.
return table5[j - t4] & MASK;
}