Thursday, May 7, 2026
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!
RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6891 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12105 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6962 POSTS0 COMMENTS