// Generate 50 random numbers between 0 and 500 ([0500)
Int number = 0;
For (INT I = 0; I <50; I ++)
{
Number = (INT) (math. Random () * 500 );
This. Numbers. insert (number); // insert in empty list
}
Each operation can generate 50 random numbers (not sure if there may be duplicates ),
In addition, the running result is different every two times, and you do not need to set a seed like C ++.
The following is an encapsulation that is easier to use.Code: Private Static int getrandomvalue (INT lowerbound, int upperbound) {int retval = lowerbound; If (lowerbound! = Upperbound) {If (lowerbound> upperbound) {int TMP = lowerbound; lowerbound = upperbound; upperbound = TMP;} retval = lowerbound + (INT) (math. random () * (upperbound-lowerbound + 1);} return retval ;}
Reference: http://zhidao.baidu.com/question/93760119.html? Fr = ala0
More complex code can be referred to: http://www.cnblogs.com/Fskjb/archive/2009/08/29/1556417.html