Expectation-based mechanism looks good, except that it should be returning the ceiling of the expectation instead of whatever the default double-to-int rounding rules are in Scala (apparently sometimes floor).