Ori.livneh has submitted this change and it was merged.
Change subject: Fix off-by-one error; simplify sampling code.
......................................................................
Fix off-by-one error; simplify sampling code.
I was initially reluctant to use 0 as a magic value for simple random
sampling because I reasoned that it is would be easy to write code that
is broken somehow and unintentionally returns 0. But it would be just as
easy to get things wrong and have the random function be unintentionally
idempotent. This way of doing it seems cleaner and saner to me.
Change-Id: I69725abb7643f30173fa658fe85219fa96e86705
---
M modules/ext.navigationTiming.js
1 file changed, 1 insertion(+), 5 deletions(-)
Approvals:
Ori.livneh: Verified
Mattflaschen: Looks good to me, approved
diff --git a/modules/ext.navigationTiming.js b/modules/ext.navigationTiming.js
index 7aff935..920d4b7 100644
--- a/modules/ext.navigationTiming.js
+++ b/modules/ext.navigationTiming.js
@@ -10,16 +10,12 @@
var timing = window.performance ? performance.timing : null;
- function getRand( n ) {
- return Math.floor( Math.random() * ( n + 1 ) );
- }
-
function inSample() {
var factor = mw.config.get( 'wgNavigationTimingSamplingFactor'
);
if ( !$.isNumeric( factor ) || factor < 1 ) {
return false;
}
- return getRand( factor ) === getRand( factor );
+ return Math.floor( Math.random() * factor ) === 0;
}
function emitTiming() {
--
To view, visit https://gerrit.wikimedia.org/r/53952
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I69725abb7643f30173fa658fe85219fa96e86705
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/NavigationTiming
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits