3 ms·
Article says "Math.log(new Random().nextDouble()) generates a random number between -1 (exclusive) and 0", this seems a mistake. Actually this gives you any ne
by csense 3y ago
Article says "Math.log(new Random().nextDouble()) generates a random number between -1 (exclusive) and 0", this seems a mistake. Actually this gives you any negative number. If you negate the output (i.e. -log(rand())) you get an exponential distribution,
According to the linked paper, an exponential distribution is actually optimal. (The paper defines "expiration gap" to be how much earlier than normal a key expires. The paper proves that, for any fixed allowance of expected expiration gap, an exponential distribution minimizes the expected stampede size.)
- areyohrahul 3y agoThanks for pointing this out. I've corrected this in the article now.