Getting a random number between a min and a max I have a function that gets a random number between a min and max.

I call the function on a variable as such:

let randomPage = getRandomIntInclusive(1, 5);


That expression is repeated several times in my code (let's say 5 to 10 times within different functions). Is there a way to refactor it further or call it in a better way?

The way I call it is like:

function a() {
  randomPage = getRandomIntInclusive(1, 5);
}

function b() {
  randomPage = getRandomIntInclusive(1, 5);
}

function c() {
  randomPage = getRandomIntInclusive(1, 5);
}


Full code:

$http({
  method: "GET",
  url: "URL"
})
.then(function mySuccess(response) {
  $scope.discoverMovie = response.data;
  /* console.log($scope.discoverMovie);
  console.log($scope.discoverMovie.results[0].id); */
  var i = getRandomIntInclusive(1, $scope.discoverMovie.results.length - 1);
  trailerKey = $scope.discoverMovie.results[i].id;
  getMovieDetail(trailerKey);

  $scope.nextMovie = function () {
    /* Get Movie to Next Movie Function */
    i = i + 1;
    if (i == $scope.discoverMovie.results.length) {
      randomPage = getRandomIntInclusive(1, 5);
      i = getRandomIntInclusive(1, $scope.discoverMovie.results.length - 1);
      getMovieList(randomPage);
    }
    trailerKey = $scope.discoverMovie.results[i].id;
    getMovieDetail(trailerKey);
  };

  $scope.previousMovie = function () {
    /* Get Movie to Next Movie Function */
    i = i - 1;
    if (i &lt; 0) {
      randomPage = getRandomIntInclusive(1, 5);
      i = getRandomIntInclusive(0, $scope.discoverMovie.results.length - 1);
      getMovieList(randomPage);
    }
    trailerKey = $scope.discoverMovie.results[i].id;
    getMovieDetail(trailerKey);
  };
}, function myError(response) {
    $scope.discoverMovie = response.statusText;
 });
You can abstract the code in another function and then call it. 

If you are using OOP, then you can either pull that in (abstract) Parent class, this way it would be accessible to everyone. 

function getRandomPageNumber(){
    return getRandomIntInclusive(1, 5);
}