Created
August 2, 2013 17:47
-
-
Save sandeep45/6141850 to your computer and use it in GitHub Desktop.
create random number with weighted average
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script> | |
// give number between 1 and 100 | |
function getRandomNumber(){ | |
return Math.floor(Math.random()*100)+1 | |
} | |
// ** config starts **// | |
var b = "1"; // show to 20% of customer | |
var sample_size = 40000; | |
// ** config ends **// | |
var show_count = 0; | |
var hide_count = 0; | |
for(i=0;i<sample_size;i++){ | |
random_number = getRandomNumber(); | |
if (random_number <= b){ | |
show_count = show_count+1; | |
}else{ | |
hide_count = hide_count+1; | |
} | |
} | |
console.log("Config: you wanted to show: ", b, "% of the times and are testing with sample size: ", sample_size); | |
console.log("RESULT:"); | |
console.log("shown count: ", show_count); | |
console.log("hide count: ", hide_count); | |
console.log("you actually showed: ", (show_count/sample_size)*100, "% of the times" ); | |
</script> | |
</head> | |
<body> | |
<body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment