biased/biased.js
function select(elems) {
	var r = Math.random();
	var ref = 0;

	for(var i=0; i < elems.length; i++) {
		var elem= elems[i];
		ref += elem[1];
		if (r < ref) return elem[0];
	}

	// This happens only if probabilities don't add up to 1
	return null;
}
function select(elems) {
	var r = Math.random();
	var ref = 0;

	for(var i=0; i < elems.length; i++) {
		var elem= elems[i];
		ref += elem[1];
		if (r < ref) return elem[0];
	}

	// This happens only if probabilities don't add up to 1
	return null;
}
function select ( elems ) { var r = Math . random ( ) ; var ref = 0 ; for ( var i = 0 ; i < elems . length ; i ++ ) { var elem = elems [ i ] ; ref += elem [ 1 ] ; if ( r < ref ) return elem [ 0 ] ; } // This happens only if probabilities don't add up to 1 return null ; }
Biased random entry selection
Biased random entry selection