Open In App

Fabric.js getRandomInt() Method

Last Updated : 03 Feb, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads