Thursday, July 4, 2024
HomeLanguagesJavascriptFabric.js getRandomInt() Method

Fabric.js getRandomInt() Method

The getRandomInt() method is used to return a random number between two specified number.

Syntax:

getRandomInt(min, max)

Parameters: This method accepts two parameters as mentioned above and described below:

  • min: This parameter holds the specified lower limit value.
  • max: This parameter holds the specified upper limit value.

Return Value: This method returns the random number between min and max value (including). The output changes everytime you run the input file.

Example 1:

Javascript




<!DOCTYPE html>
<html>
  
  <head>
     <!-- Adding the FabricJS library -->
     <script src=
     </script>
  </head>
  
  <body>
    <script type="text/javascript">
  
      // Calling getRandomInt() function over
      // some specified min and max values
      console.log(fabric.util.getRandomInt(1, 1));
      console.log(fabric.util.getRandomInt(1, 2));
      console.log(fabric.util.getRandomInt(1, 4));
      console.log(fabric.util.getRandomInt(2, 10));
    </script>
  </body>
  
</html>


Output:

1
2
2
8

Example 2:

Javascript




<!DOCTYPE html>
<html>
  
  <head>
     <!-- Adding the FabricJS library -->
     <script src=
     </script>
  </head>
  
  <body>
    <script type="text/javascript">
  
      // Specifying some min and max values
       var min1 = 1;
       var max1 = 4;
       var min2 = 12;
       var max2 = 20;
  
      // Calling getRandomInt() function over
      // the above specified min and max values
      console.log(fabric.util.getRandomInt(min1, max1));
      console.log(fabric.util.getRandomInt(min2, max2));
    </script>
  </body>
  
</html>


Output:

2
19

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!

Nokonwaba Nkukhwana
Experience as a skilled Java developer and proven expertise in using tools and technical developments to drive improvements throughout a entire software development life cycle. I have extensive industry and full life cycle experience in a java based environment, along with exceptional analytical, design and problem solving capabilities combined with excellent communication skills and ability to work alongside teams to define and refine new functionality. Currently working in springboot projects(microservices). Considering the fact that change is good, I am always keen to new challenges and growth to sharpen my skills.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments