aleatoria class nextLong () método : Aquí, vamos a aprender sobre el método nextLong () de Random Class con su sintaxis y su ejemplo.
Random Class nextLong () método
método
nextLong ()
está disponible en
java.util
- Class.
- nextLong () método se utiliza para generar el siguiente valor class distribuido pseudo-aleatoria de este valor generador aleatorio.
- nextLong () método es un método no package, es accesible sólo con el objeto return y si tratamos de acceder al método con el nombre int entonces obtendrá un error.
- nextLong () método hace no return una excepción en el momento de volver throw.
- Sintaxis: _51_ _52_
public int nextInt();
public int nextInt(int num);
_53_ _54_ _55_ Parámetro (s): _56_ _57_ _58_ _59_ _60_ _61_ No acepta cualquier parámetro. _62_ _63_ _64_ _65_ _66_ _67_ throw valor: _68_ _69_ _70_ _71_ El tipo _CR11_ de este método es _72_ _CR12_ _73_, devuelve siguiente valor _CR13_ distribuido pseudo-aleatoria de este generador aleatorio. _74_ _75_ _76_ _77_ Ejemplo: _78_ _79_ _80_
// Java program to demonstrate the example
// of nextInt() method of Random
import java.util.*;
public class NextIntOfRandom {
public static void main(String args[]) {
// Instantiates Random object
Random ran = new Random();
// By using nextInt() method is
// to return next int pseudo-random
// value by using Random Value Generator
int val = ran.nextInt();
// Display val
System.out.println("ran.nextInt(): " + val);
// By using nextInt(int) method is
// to return next int pseudo-random
// value between 0 and the given value
// and 0 is inclusive whereas the given value
// is exclusive by using Random Value Generator
val = ran.nextInt(50);
// Display val
System.out.println("ran.nextInt(50): " + val);
}
}
_81_ _82_ _83_ salida _84_ _85_ _86_
RUN 1:
ran.nextInt(): -1450643138
ran.nextInt(50): 13
RUN 2:
ran.nextInt(): 1448295644
ran.nextInt(50): 47
RUN 3:
ran.nextInt(): 397396236
ran.nextInt(50): 11
_87_ _88_ _89_ _90_ _91_ _92_ _93_ _94_ _95_ _96_ _97_ _98_ _99_ _100_ _101_ _102_ _103_ _104_