Back to project page dice-probabilities.
The source code is released under:
MIT License
If you think the Android project dice-probabilities listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.kleemann.diceprobabilities.special; // w w w.ja v a 2 s.co m import org.apache.commons.math3.fraction.BigFraction; import org.kleemann.diceprobabilities.R; import org.kleemann.diceprobabilities.distribution.Distribution; import org.kleemann.diceprobabilities.distribution.ScaleCumulativeDistribution; import android.content.res.Resources; import android.util.SparseIntArray; /** * <p> * If the first roll succeeds, you must successfully roll again in order to * succeed. */ class ForcedRerollSpecial extends AbstractSpecial { public ForcedRerollSpecial(Resources r) { super(r.getString(R.string.special_forced_reroll_title), r .getString(R.string.special_forced_reroll_description)); } @Override public Distribution getDistribution(SparseIntArray sidesToCount) { Distribution d = super.getDistribution(sidesToCount); return ScaleCumulativeDistribution.scale(d, new ScaleCumulativeDistribution.Scale() { public BigFraction scale(BigFraction pS, int x) { // P(S) = 1 - P(F) // P(new) = 1 - ( P(F) + P(S) * P(F) ) final BigFraction pF = BigFraction.ONE.subtract(pS); return BigFraction.ONE.subtract(pF.add(pS.multiply(pF))); } }); } }