Thursday, September 4, 2025
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

Most Popular

Dominic
32260 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6625 POSTS0 COMMENTS
Nicole Veronica
11795 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11855 POSTS0 COMMENTS
Shaida Kate Naidoo
6747 POSTS0 COMMENTS
Ted Musemwa
7023 POSTS0 COMMENTS
Thapelo Manthata
6694 POSTS0 COMMENTS
Umr Jansen
6714 POSTS0 COMMENTS