ExtensionMethod.NET Home of 880 C#, Visual Basic, F# and Javascript extension methods

randomize()

Generates random number with appointed limit.

Source

function randomize(limit){
  var a = Math.pow(10, String(limit).length); 
  var readyNumber = Math.floor(Math.random()*a);
  if(readyNumber>=limit){
    return randomize(limit);
  } else {
    return readyNumber;
  }
}

Example

var randomNumber = randomize(44);
document.write("Random number: "+randomNumber);

Author: Adam S.

Submitted on: 6 apr. 2015

Language: JavaScript

Type: Math.random()

Views: 4112