title: Save the value of a function in a variable, which returns random values
body: <p>I´d like to save the value of a function, which returns random values from an .xml file in a variable and update the variable everytime a new value is generated by the function.</p>
  
  <p>To illustrate: This is my function</p>
  
  <pre><code>function getNewValue() {
  return videos[Math.floor(Math.random() * videos.length)];
  }
  </code></pre>
  
  <p>I´d like to save the value which was generated in a variable e.g "currentValue", so everytime the function is called, the "currentValue" changes to the value which was generated.</p>
  
  <p>Something like:</p>
  
  <pre><code>var currentValue;
  function getNewValue() {
  return videos[Math.floor(Math.random() * videos.length)];
  currentValue = getNewValue();
  }
  </code></pre>
  
  <p>won´t work because the function generates a new value which isn´t the old one..</p>
  
  <p>any ideas? Thank you</p>