Last active
November 3, 2017 16:05
-
-
Save justinledwards/0fe8d5df561cfa4d0bf4c821e032d431 to your computer and use it in GitHub Desktop.
Random Sample
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> | |
<title>Random Sample</title> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> | |
</head> | |
<body> | |
<label>Range Start: </label> <input id="range_start" value="1"></input> | |
<label>Range End: </label> <input id="range_end" value="100"></input> | |
<label>Sample Size: </label> <input id="sample_size" value="50"></input> | |
<button id="generate">Generate</button> | |
<p><textarea rows="10" cols="50" id="output"></textarea><p> | |
<script> | |
var arr = [1,2,3,4,5,6]; | |
range_start = 1 | |
range_end = 100 | |
sample_size = 50 | |
$("#generate").click(function(){ | |
range_start = parseInt($("#range_start").val()) | |
range_end = parseInt($("#range_end").val())+1 | |
sample_size = parseInt($("#sample_size").val()) | |
arr = _.range(range_start, range_end) | |
arr = _.sample(arr, sample_size) | |
arr = arr.sort(function(a, b){return a-b}) | |
$("#output").val(arr) | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment