Is it possible to create a truly random number in JavaScript?
I have tried here jsfiddle
Javascript:
// Mouse coordinates on click
var mouseX;
var mouseY;
$(document).ready(function(){
$("#btn1").click(function(e){
mouseX = e.clientX;
mouseY = e.clientY;
});
});
// Timing mouse down
var pressed;
var duration;
$(document).ready(function(){
$("#btn1").on("mousedown", function(){
pressed = +new Date();
});
$("#btn1").on("mouseup", function(){
duration = +new Date() - pressed;
});
});
// Time since last click
var loaded;
var onPush;
$(document).ready(function(){
loaded = +new Date();
$("#btn1").on("mousedown", function(){
onPush = +new Date() - loaded;
loaded = +new Date();
});
});
// Extending process for pseudorandom number? or creating a truly random number?
$(document).ready(function(){
$("#btn1").on("click", function(){
function rnum(min, max) {
var a = Math.random();
var ranMouseX = mouseX * a;
var ranMouseY = mouseY * a;
var ranDuration = duration * a;
var ranOnPush = onPush * a;
var combine = ((ranMouseX / ranOnPush) + (ranMouseY / ranDuration) % a);
$("#p1").text(((combine - Math.floor(combine)) * (max-min) + min).toFixed(0))
};
var f = document.getElementById('min');
var g = document.getElementById('max');
rnum(parseInt(f.value), parseInt(g.value));
});
});
But have I just extended the process for a pseudo-random number? or does this make a truly random number?
If it is still just a pseudo-random number how can I make a truly random number in JavaScript?
Math.random()is just fine, don't really understand what you're looking for. From that original random number, just perform some calculation/computation to get your own random numbers (with such as greater values, ...).