Recently, when publishing a private server, the customer requested random ad sorting and implementation on the html page, that is, javascript must be used. First, you need to generate random numbers not repeated within n, and put the generated random numbers into another Array. Use the following method to complete the process:
The Code is as follows:
Function getRandomNumbers (count)
{
Var numbers = new Array ();
Var original = new Array ();
For (var I = 0; I
{
Original [I] = I + 1;
}
Original. sort (function () {return 0.5-Math. random ();});
For (var I = 0; I
{
Numbers [I] = original [I]-1;
}
Return numbers;
}
Then, in the background program, output the html Script:
The Code is as follows:
Var sf = new Array ();
Sf [0] ='Server NameServer IP AddressOpening TimeLine TypeVersion IntroductionCustomer service QQDetails';
Sf [1] ='Server NameServer IP AddressOpening TimeLine TypeVersion IntroductionCustomer service QQDetails';
Use the previous method to generate a random number and display the html Script according to the random number.
The Code is as follows:
Var numbers = getRandomNumbers (sf. length );
For (I = 0; I {
Document. write (sf [numbers [I]);
}