mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-21 16:01:17 -04:00
commit all random stuff to repo
This commit is contained in:
43
static/candies/scripts/random.js
Executable file
43
static/candies/scripts/random.js
Executable file
@@ -0,0 +1,43 @@
|
||||
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;
|
||||
}
|
||||
},
|
||||
|
||||
};
|
Reference in New Issue
Block a user