reload a page with random numbers in adress

Subscribe to reload a page with random numbers in adress 3 posts, 3 voices

rene1879 User

Hi,

I'm searching for a script reloading a page containing with different adresses using random numbers, eg. http://www.test.com/1 (1 should represent the random number).

Rene

 
JoeSimmons Scriptwright

var max_num = 50;
var num = Math.ceil(Math.random()*max_num);
location.href = 'http://' + document.domain + '/' + num;

 
Aquilax Scriptwright

It depends from the range of the random number:


var maxValue=50;
var randomNumber=Math.random(); //Range 0-1;
var range1=Math.floor(maxValue*randomNumber); //Range 0-49
var range2=Math.ceil(maxValue*randomNumber); //Range 1-50
var range3=Math.round(maxValue*randomNumber); //Range 0-50, but 0 and 50 have half probability than all other numbers 

//this works also fine
location.pathname=range1; //or range2 or range3

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel