Wondering if anyone could tell me what this snippet of code does
Code:<script>
var r = Math.random();
r=r*50;
if(r>49)
document.location.href="http://www.example.com/somefile.htm";
</script>
Printable View
Wondering if anyone could tell me what this snippet of code does
Code:<script>
var r = Math.random();
r=r*50;
if(r>49)
document.location.href="http://www.example.com/somefile.htm";
</script>
It looks like it's randomly redirecting site visitors to another page, but only if the lucky draw number is greater than 49, which I assume it would be in most cases since r is a randomly picked number to begin with.
It redirects the site. I beleive if r is greater than 49, then the site will redirect to the site above.
What if it was put like this providing this is the correct format what would this do
Code:<script>document.write<script>
var r = Math.random();
r=r*50;
if(r>49)
document.location.href="http://www.example.com/somefile.htm";
</script>;</script>
This commented version actually works and you can watch it's output. :)
In effect, it loads somefile.htm 2% of the time. This code is probably used for cookie stuffing.Code:<script>
// Generate a random number between 0 and 1
var r = Math.random();
// Print the random number
document.write(r);
// Print a hyphen to separate this number from the next number
document.write(" - ");
// Multiply the number times fifty, to make a number between 0 and 49.9999999999~
r=r*50;
// Print the new random number
document.write(r);
// If the random number is 49 or higher, load somefile.htm; If not -- do nothing
if(r>49)
document.location.href="http://www.example.com/somefile.htm";
</script>