Skip to content

Instantly share code, notes, and snippets.

@fischerbach
Last active December 24, 2019 10:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fischerbach/df9113cf5e67f82791dc3bb464ef5d04 to your computer and use it in GitHub Desktop.
Save fischerbach/df9113cf5e67f82791dc3bb464ef5d04 to your computer and use it in GitHub Desktop.
uniform
<h1>[Statistics] Min of two uniform random variables: Google [Medium]</h1>
<div>Say we have X ~ Uniform(0, 1) and Y ~ Uniform(0, 1). What is the expected value of the minimum of X and Y?</div>
<div>
<input id="ATTEMPTS" />
</div>
<div id="result">
<ol id="results">
</ol>
</div>
const ATTEMPTS = 1;
document.getElementById("ATTEMPTS").addEventListener("keydown", function(){
calculate(
parseInt(this.value),
Math.random,
Math.random
)
}, false);
var calculate = function (attempts, dist_x, dist_y) {
var X = 0
var Y = 0
var results = []
var sum = 0;
for(var i=0; i <= attempts; i++) {
X = Math.random();
Y = Math.random();
results[i] = Math.min(X,Y);
sum += results[i];
document.getElementById('results').innerHTML = "";
document.getElementById('results').appendChild((function(r){
r.appendChild(document.createTextNode(ATTEMPTS+X+" | "+Y+" | " + sum));
return r;
})(document.createElement('li')));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment