Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var randomizer = function () {
- return Math.random() > 0.02;
- };
- var randomizer = {
- _ratio: 0.02, // default ratio
- setRatio: function (falses, total) {
- this._ratio = falses / total;
- },
- getResult: function () {
- return Math.random() > this._ratio;
- }
- };
- randomizer.getResult();
- randomizer.setRatio(60, 1000); // 60 out of 10000
- function mostlyFalse() {
- return Math.random() <= 0.05;
- }
- //Get random number from 1 to 20, if equals 20 return false
- if (Math.floor((Math.random()*20)+1) == 20)
- {
- return false;
- }
- else{
- return true;
- }
- function suchRandom(chanceInPercent){
- return Math.random() > chanceInPercent/100;
- }
- console.log(suchRandom(2)); //because 1000/50 = 20 true / 1000 calls = 2%
- function foo () { return Math.random() > 0.02; }
- // 1 / 50 == 0.02, so if it's less than 0.02 return false
- var num = Math.floor((Math.random()*50)+1);
- function chance( c = 0.5 ){
- return Math.random() < c;
- }
- // Block has a 60% chance of being executed.
- if( chance( .6 ) ){
- //Do stuff
- }
- // Or, to solve your problem specifically
- var c = chance( 49 / 50 );
- var c = 0;
- function f()
- {
- return ++c % 50 == 0 ? false : true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement