cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <h2>Click button for random number</h2>
<p id="num1"></p>
<button id="b1">Between 0 and 1</button> 

<p id="num2"></p>
<button id="b2">Between 1 and 3</button>

<p id="num3"></p>
<button id="b3">Between 1 and 20</button>
            
          
!
            
              //return number between 0 and 1
function randomNum(){
  var currentTime = new Date();
  var currentHours = currentTime.getHours();
  var currentMinutes = currentTime.getMinutes();
  var currentSeconds = currentTime.getSeconds();
  var currentMiliSeconds = currentTime.getMilliseconds();
  var timeVal = currentHours * currentMinutes * currentSeconds * currentMiliSeconds;
  
  var maxVal = 23 * 59 * 59 * 999;
  var stringNum = String(timeVal / maxVal);
  var editedNum = stringNum.slice(3,16);
  var finalNum = Number(editedNum) / 1e13;
 
  return finalNum;
}

document.getElementById("b1").addEventListener("click", function(){
  document.getElementById("num1").innerText = randomNum();
});
  
document.getElementById("b2").addEventListener("click", function(){
  document.getElementById("num2").innerText = Math.floor(randomNum() * 3) + 1;
});

document.getElementById("b3").addEventListener("click", function(){
  document.getElementById("num3").innerText = Math.floor(randomNum() * 20) + 1;
});

            
          
!
999px
Loading ..................

Console