title: Get random number in ng-repeat angular
body: <p>I need to get a random number in my cycle angular. I tried this in my template:</p>
  
  <pre><code>   &lt;div ng-app="app" ng-controller="Base" &gt;
      &lt;div ng-repeat="item in items"&gt;
        &lt;img ng-src="/img/img{{getRandomImg()}}.png"&gt; 
      &lt;/div&gt;
     &lt;/div&gt;
  </code></pre>
  
  <p>And function in my Base controller:</p>
  
  <pre><code>$scope.getRandomImg = function(){
      return Math.floor((Math.random()*3)+1);
  }
  </code></pre>
  
  <p>When my page loaded i have error:
  <strong>$rootScope:infdig Infinite $digest Loop</strong>    </p>
  
  <p>I also tried to do this with the directive</p>
  
  <pre><code>app.directive('randomImage', [
      function() {
          return {
              restrict: 'A',
              link: function($scope, element, attrs) {
                  var rand = Math.floor((Math.random()*3)+1);
  
                  $(element).attr('src', '/img/tracks/trackimg'+rand+'.png');
              }
          }
  
      }
  ]);
  </code></pre>
  
  <p>And in my template:</p>
  
  <pre><code> &lt;div ng-app="app" ng-controller="Base" ng-repeat="item in items"&gt;
        &lt;img data-random-image=""&gt; 
   &lt;/div&gt;
  </code></pre>
  
  <p>It works almost correctly. BUT when I update <code>items</code> in my controller is not re-generated images, but remain the same. Why?</p>