JAVA - random number

2006-12-08 5:03 pm
do anyone know how can i get a random number from java and use it in several times?
i know how to get a random number by using
Math.random(); or gen.random...
but i dun know how can i use the number for three times and then get a new random number?
or the JAVA have no such way?

回答 (1)

2006-12-08 6:09 pm
✔ 最佳答案
what do u mean? can u store the random number to another variable and generate it?
try following code.

import java.util.Random;

public class GenRand
{ public static void main( String[] args )
{ Random ran = new Random();
int i1 = 0;
int i2 = 0;
int i3 = 0;

i1 = ran.nextInt( );
i2 = ran.nextInt( );
i3 = ran.nextInt( );

System.out.println( i1 );
System.out.println( i2 );
System.out.println( i3 );
}
}


hope can help u


收錄日期: 2021-04-13 16:21:32
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20061208000051KK00575

檢視 Wayback Machine 備份