title: Random CSS animation time on each iteration
body: <p>Trying to set a random animation time on each iteration. I set a CSS custom property <code>--animation-time</code> changed randomly each animation iteration with JS.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let square = document.getElementById('square');
  let time;
  
  square.addEventListener('animationiteration', duration);
  
  function duration() {
    time = Math.random() + 1;
    square.style.setProperty('--animation-time', time + 's');
    console.log(time);
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>:root {
    --animation-time: 5s;
    --color-1: #ff0000;
    --color-2: #ffee00;
  }
  
  @keyframes fire {
    0% {
      background-color: var(--color-1);
    }
    100% {
      background-color: var(--color-2);
    }
  }
  
  #square {
    width: 100px;
    height: 100px;
    animation: fire var(--animation-time) ease alternate infinite;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="square"&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The duration of animation is set to <code>time = Math.random() + 1;</code> so, the iterations should never have less than 1 second. However, it hapens sometimes very quickly. Why?</p>
  
  <p>Here is a CodePen: <a href="https://codepen.io/aitormendez/pen/YbvvKw" rel="nofollow noreferrer">https://codepen.io/aitormendez/pen/YbvvKw</a></p>