mirror of
https://github.com/2009scape/2009scape.github.io.git
synced 2024-11-20 01:42:41 +01:00
44 lines
1.2 KiB
JavaScript
44 lines
1.2 KiB
JavaScript
var random = {
|
|
|
|
flipACoin : function(){
|
|
if(Math.random() < 0.5) return true;
|
|
return false;
|
|
},
|
|
|
|
oneChanceOutOf : function(n){
|
|
if(this.getRandomIntUpTo(n - 1) == 0) return true;
|
|
else return false;
|
|
},
|
|
|
|
getRandomFloat : function(){
|
|
return Math.random();
|
|
},
|
|
|
|
pickRandomly : function(array){
|
|
return array[Math.floor(Math.random()*array.length)];
|
|
},
|
|
|
|
getRandomIntUpTo : function(n){
|
|
return Math.floor(Math.random()*(n+1));
|
|
},
|
|
|
|
getRandomLetter : function(){
|
|
var possible = "abcdefghijklmnopqrstuvwxyz";
|
|
|
|
return possible.charAt(Math.floor(this.getRandomFloat() * possible.length));
|
|
},
|
|
|
|
pure : function(){
|
|
return Math.floor(Math.pow(10, random.getRandomIntUpTo(100)) * random.getRandomFloat());
|
|
},
|
|
|
|
pure2 : function(){
|
|
switch(random.getRandomIntUpTo(2)){
|
|
case 0: return Math.floor(Math.pow(10, random.getRandomIntUpTo(100)) * random.getRandomFloat()); break;
|
|
case 1: return -Math.floor(Math.pow(10, random.getRandomIntUpTo(100)) * random.getRandomFloat()); break;
|
|
case 2: return "bug"; break;
|
|
}
|
|
},
|
|
|
|
};
|