Last night I read an article on how Java developers think about JavaScript on IBM. I found that as a Java developer, I must understand and be proficient in JavaScript. after all, JavaScript is very powerful. After Jquery, Ext, and other plug-ins are injected. it has been gradually favored by Java developers again.
As required by the project, a method for generating random numbers is specially compiled, which is not repeated.
The Code is as follows:
Java code
// Define an array for storing the random numbers generated
Var array = new Array ();
// Generate a random number N times in a loop
For (var I = 0; I ++ ){
// Generate only 10 random numbers
If (array. length <10 ){
GenerateRandom (10 );
} Else {
Break;
}
}
// Cyclically traverse the random number Array
For (var I = 0; I <array. length; I ++ ){
Alert (array [I]);
}
// Method for generating random numbers
Function generateRandom (count ){
Var rand = parseInt (Math. random () * count );
For (var I = 0; I <array. length; I ++ ){
If (array [I] = rand ){
Return false;
}
}
Array. push (rand );
}
Copy to the developer tool in the FireFox browser: Run in "" to view the result.
Author: "pThinking. tk, www.soThinking.org, sothinking. tk"