Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to generate random number using Javascript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 350
    Comment on it

    In Javascript you have a number of functions to genrate random numbers between two given digits. Some of them are inbulit and some you can create for your own, But the simplest way to perform the operation is the code below:-

    // Returns a random integer between min and max
    
    function getRandomInt(min, max) {
      return Math.floor(Math.random() * (max - min + 1)) + min;
    }
    

    And this way it will perfom

    // 5 - 20
    Math.floor(Math.random() * 16) + 5;
    

    Source: Mozilla Developers

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: