-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeneradorRandomConSemillaNumerica.java
41 lines (32 loc) · 1.24 KB
/
GeneradorRandomConSemillaNumerica.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.Random;
public class GeneradorRandomConSemillaNumerica{
/**
* public static void main(String[] args) {
GeneradorRandomConSemillaNumerica generadorRandom = new GeneradorRandomConSemillaNumerica();
// Obtener y mostrar la semilla
System.out.println("Semilla generada: " + generadorRandom.getSemilla());
// Obtener y mostrar un número pseudoaleatorio largo
long numeroAleatorioLargo = generadorRandom.generarNumeroAleatorioLargo();
System.out.println("Número Aleatorio Largo: " + numeroAleatorioLargo);
}
* @param args
*/
private long semilla;
// Constructor: Genera una semilla numérica aleatoria
public GeneradorRandomConSemillaNumerica() {
this.semilla = generarSemillaNumericaAleatoria();
}
// Método para generar una semilla numérica aleatoria
private long generarSemillaNumericaAleatoria() {
return System.nanoTime();
}
// Método para obtener la semilla
public long getSemilla() {
return semilla;
}
// Método para generar y obtener un número pseudoaleatorio largo
public long generarNumeroAleatorioLargo() {
Random generador = new Random(semilla);
return generador.nextLong();
}
}