1、通過System.currentTimeMillis()來獲取一個(gè)當(dāng)前時(shí)間毫秒數(shù)的long型數(shù)字。
1
2
|
long a = System.currentTimeMillis(); System.out.println(a); |
2、通過Math.random()返回一個(gè)0到1之間的double值。
1
2
|
int b = ( int )(Math.random()* 99 + 1 ); System.out.println(b); |
3、通過Random類來產(chǎn)生一個(gè)隨機(jī)數(shù)。
1
2
3
|
Random random = new Random(); int c = random.nextInt( 100 )+ 1 ; System.out.println(c); |
以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持服務(wù)器之家!
原文鏈接:http://www.cnblogs.com/lkj2017/p/6794756.html