Answers.Body: <p><code>random</code> updates at the sub-frame level (so its value actually changes even during a frame, for example when motion blur is on. You can see this as you zoom in on the graph editor of a property with a random value, it keeps changing as it zooms and the time is sub-sampled more).</p>
  
  <p>To force it to update only once a second you need to use the <a href="http://adobe.ly/1DZW3md" rel="nofollow noreferrer"><code>seedRandom</code></a> function, with the <code>timeless</code> attribute set to <code>true</code>, and a <code>seed</code> that changes every second. Using <code>Math.floor(time)</code> will return a value that increases once every second, on the second.</p>
  
  <p>So something like:</p>
  
  <pre><code>seedRandom(Math.floor(time), timeless = true);
  random(45,55);
  </code></pre>
  
  <p>will create a random value that stays constant for 1 second, and </p>
  
  <pre><code>var holdTime = 5;
  seedRandom(Math.floor(time/holdTime), timeless = true);
  random(45,55);
  </code></pre>
  
  <p>will stay constant for 5 seconds - you can change the value of the variable <code>holdTime</code> to control how long the value holds for. For example to change once every frame, but not during sub-frame intervals set it to <code>holdTime = thisComp.frameDuration;</code></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-08-02T10:47:28.370Z
Answers.Text: If you want eg. 5 seconds, it's time/5
Answers.UserDisplayName: user2875404
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-08-18T07:36:59.397Z
Answers.LastActivityDate: 2017-08-03T04:11:38.597Z
Answers.LastEditDate: 2017-08-03T04:11:38.597Z
Answers.UserDisplayName: stib
Body: <p>In After Effects I am trying my hands at this <div class="youtube-embed"><div>
                  <iframe width="640px" height="395px" src="https://www.youtube.com/embed/KLsk3lGbiVc?start=0"></iframe>
              </div></div> and would like to add a random number between 45 and 55 in the upper right corner, which should change each second.</p>
  
  <p>If I use Math.round(random(45,55)) I am getting pretty close, but the number updates maybe 20 times a second making it unusable. Is there a way to control how often a new number is generated? Is there another way to do this?</p>
  
  <p>Just to clarify, I want sort of what is already in wiggle, where wiggle(1,30) wiggles once a second.</p>
  
Tags: <after-effects>
Title: Create a random number each second
UserDisplayName: user11451
ThreadText: # Create a random number each second
  
  (Asked by: username_0 on 2015-08-17)
  
  In After Effects I am trying my hands at this
  
  and would like to add a random number between 45 and 55 in the upper right corner, which should change each second.
  
  If I use Math.round(random(45,55)) I am getting pretty close, but the number updates maybe 20 times a second making it unusable. Is there a way to control how often a new number is generated? Is there another way to do this?
  
  Just to clarify, I want sort of what is already in wiggle, where wiggle(1,30) wiggles once a second.
  
  **Tags:** after-effects
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-08-18. Score: 3 | Accepted answer
  
  `random` updates at the sub-frame level (so its value actually changes even during a frame, for example when motion blur is on. You can see this as you zoom in on the graph editor of a property with a random value, it keeps changing as it zooms and the time is sub-sampled more).
  
  To force it to update only once a second you need to use the [`seedRandom`](http://adobe.ly/1DZW3md) function, with the `timeless` attribute set to `true`, and a `seed` that changes every second. Using `Math.floor(time)` will return a value that increases once every second, on the second.
  
  So something like:
  
  ```
  seedRandom(Math.floor(time), timeless = true);
  random(45,55);
  
  ```
  
  will create a random value that stays constant for 1 second, and
  
  ```
  var holdTime = 5;
  seedRandom(Math.floor(time/holdTime), timeless = true);
  random(45,55);
  
  ```
  
  will stay constant for 5 seconds - you can change the value of the variable `holdTime` to control how long the value holds for. For example to change once every frame, but not during sub-frame intervals set it to `holdTime = thisComp.frameDuration;`
  
  > **Comments:**
  > **username_2**: If you want eg. 5 seconds, it's time/5  
  
  ---
  
  