public class RandomNumberDemo
{
public static void getTime()
{
long start = System.currentTimeMillis();
runCode();
long end = System.currentTimeMillis();
System.out.println("本次運(yùn)行所用時(shí)間是:"+(end-start));
}
/*public static void runCode()
{
for(int i=0; i<10000; i++)
{
System.out.println(i);//9999 本次運(yùn)行所用時(shí)間是:185
}
}*/
/*public static void runCode()
{
int b=0;
for(int i=0; i<10000; i++)
{
//[9999] 本次運(yùn)行所用時(shí)間是:244
b = (int) Math.round(Math.random()*10);//而產(chǎn)生0和10之間的整數(shù),則會(huì)寫(xiě)成: Math.round(Math.random()*10)
System.out.println("["+i+"]"+b);
}
}*/
public static void runCode()
{
int c=0;
for(int i=0; i<10000; i++)
{
c= java.util.concurrent.ThreadLocalRandom.current().nextInt(100);//本次運(yùn)行所用時(shí)間是:243
System.out.println("["+i+"]"+c);
}
}
public static void main(String[] args)
{
RandomNumberDemo.getTime();
}
}