Skip to content

Commit a5287e7

Browse files
author
efve.zff
committed
runtime: fix comments about inverse transform sampling in fastexprand
1 parent d000963 commit a5287e7

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/runtime/malloc.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1837,12 +1837,12 @@ func fastexprand(mean int) int32 {
18371837
return 0
18381838
}
18391839

1840-
// Take a random sample of the exponential distribution exp(-mean*x).
1841-
// The probability distribution function is mean*exp(-mean*x), so the CDF is
1842-
// p = 1 - exp(-mean*x), so
1843-
// q = 1 - p == exp(-mean*x)
1844-
// log_e(q) = -mean*x
1845-
// -log_e(q)/mean = x
1840+
// Take a random sample of the exponential distribution exp(-x/mean).
1841+
// The probability distribution function is exp(-x/mean)/mean, so the CDF is
1842+
// p = 1 - exp(-x/mean), so
1843+
// q = 1 - p == exp(-x/mean)
1844+
// log_e(q) = -x/mean
1845+
// -log_e(q) * mean = x
18461846
// x = -log_e(q) * mean
18471847
// x = log_2(q) * (-log_e(2)) * mean ; Using log_2 for efficiency
18481848
const randomBitCount = 26

0 commit comments

Comments
 (0)