Skip to content

runtime: fix comments about inverse transform sampling in fastexprand #73633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/runtime/malloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -1837,12 +1837,12 @@ func fastexprand(mean int) int32 {
return 0
}

// Take a random sample of the exponential distribution exp(-mean*x).
// The probability distribution function is mean*exp(-mean*x), so the CDF is
// p = 1 - exp(-mean*x), so
// q = 1 - p == exp(-mean*x)
// log_e(q) = -mean*x
// -log_e(q)/mean = x
// Take a random sample of the exponential distribution exp(-x/mean).
// The probability distribution function is exp(-x/mean)/mean, so the CDF is
// p = 1 - exp(-x/mean), so
// q = 1 - p == exp(-x/mean)
// log_e(q) = -x/mean
// -log_e(q) * mean = x
// x = -log_e(q) * mean
// x = log_2(q) * (-log_e(2)) * mean ; Using log_2 for efficiency
const randomBitCount = 26
Expand Down