object that simulates a dice as a random number generator without replacement.
//Random number generator object called dice, which returns and records every generated number.
var dice = function (max) {
this.ceiling = max;
this.results = [];
this.roll = function() {
var choice = Math.floor((Math.random() * this.ceiling) + 1);
this.results.push(choice);
return choice;
}
}
//Gives a certain amount of trials for a dice, with replacement(prob stays the same)
function roll_times(trials) {
var test = new dice(6);
for(i=0;i<trials;i++) test.roll();
return test.results;
}
console.log(roll_times(30));
//[ 4, 5, 2, 1, 1, 6, 2, 3, 6, 4, 5, 6, 5, 1, 1, 3, 3, 5, 5, 5, 4, 3, 3, 3, 2, 2, 4, 4, 2, 3 ]