| new Random () | ใช้สร้าง object ของ class random |
|---|---|
| nextInt() | ใช้สุ่มเลขจำนวนเต็มระหว่าง 0 ถึง max |
| nextDouble() | ใช้สุ่มเลขที่มีทศนิยมด้วย ระหว่าง 0 ถึง 1 |
| nextLong() | ใช้สุ่มเลข |
| nextFloat() | ใช้สุ่มเลข |
method:new Random ();
return type:Random
content:ใช้สร้าง object ของ class random
example:Random rnd = new Random ();
method:nextInt ( max );
return type:int
content:ใช้สุ่มเลขจำนวนเต็มระหว่าง 0 ถึง max
example:Random rnd = new Random (); int random_number = rnd.nextInt ( 10 );
method:nextDouble ();
return type:double
content:ใช้สุ่มเลขที่มีทศนิยมด้วย ระหว่าง 0 ถึง 1
example:Random rnd = new Random (); double random_number = rnd.nextDouble ();
method:nextLong ();
return type:long
content:ใช้สุ่มเลข
example:Random rnd = new Random (); long random_long = rnd.nextLong ();
method:nextFloat ();
return type:float
content:ใช้สุ่มเลข
example:Random rnd = new Random (); float random_float = rnd.nextFloat ();