Pseudo-Random JavaScript
Just playing and did this code just for fun. Nothing fancy but does the Random job nicely. Check this out:
<button onclick="mkRandom()">GET RANDOMS</button>
<p id="demo"></p>
<script>
function mkRandom() {
var d = new Date();
var n = d.getMilliseconds();
document.getElementById("demo").innerHTML = "<br>Random 0 - 999: ";
document.getElementById("demo").innerHTML += n;
document.getElementById("demo").innerHTML += "<br>Random Binary: ";
document.getElementById("demo").innerHTML += n.toString(2);
document.getElementById("demo").innerHTML += "<br>Random Decimal 0 - 9: ";
document.getElementById("demo").innerHTML += n.toString()[0,0];
document.getElementById("demo").innerHTML += "<br>Random True[1] or False[0]: ";
if(n >= 500)
{
document.getElementById("demo").innerHTML += "TRUE [1]";
}else
{
document.getElementById("demo").innerHTML += "FALSE [0]";
}
}
</script>
<p id="demo"></p>
<script>
function mkRandom() {
var d = new Date();
var n = d.getMilliseconds();
document.getElementById("demo").innerHTML = "<br>Random 0 - 999: ";
document.getElementById("demo").innerHTML += n;
document.getElementById("demo").innerHTML += "<br>Random Binary: ";
document.getElementById("demo").innerHTML += n.toString(2);
document.getElementById("demo").innerHTML += "<br>Random Decimal 0 - 9: ";
document.getElementById("demo").innerHTML += n.toString()[0,0];
document.getElementById("demo").innerHTML += "<br>Random True[1] or False[0]: ";
if(n >= 500)
{
document.getElementById("demo").innerHTML += "TRUE [1]";
}else
{
document.getElementById("demo").innerHTML += "FALSE [0]";
}
}
</script>
Let's see:
Comments
Post a Comment
Please leave your comment! It will always be interesting!