Gera um número aleatório de 90-100 repetições:
classe pública Randomtest {public static void main (string [] args) { / * * o método Math.random () padrão de tipo de tipo duplo, por isso precisa ser lançado para int * / int x = (int) (math.random () * (100-90+1) +90); // (max-min+1)+min = min-max System.out.println (x); }}Gera números aleatórios de 90-100 não repetição:
importar java.util.hashset; importar java.util.random; importar java.util.set; public class Randomtest {public static void main (string args []) {int max = 100; // valor máximo int min = 90; // valor mínimo int conting = max-min; // Número aleatório aleatório Random = new Random (); Set <Integer> set = new HashSet <> (); // O contêiner de hashset pode armazenar apenas objetos não duplicados while (set.size () <count) {// número de elementos armazenados de inhashset int x = aleatom.nextInt (max-min+1)+min; // Crie um conjunto de números aleatórios.Add (x); // Adicione um número aleatório ao contêiner de hashset} para (int i: set) {// foreach Traversal the Container Element System.out.println (i);}}}}Um número aleatório de 90-100 repetições é gerado por segundo:
importar java.util.random; importar java.util.timer; importar java.util.timertak; public class Randomtest {void timer () {timer timer = new Timer (); // Crie o Timer.Schedule (new TimerTask () {public void run () {// TimerTask Run Method para implementar interface executável aleatória aleatória = new Random (); int x = Random.nextint (100-90+1) +90; // (max-min+1)+min = min (10090+1) +90; System.out.println (x);}}, 0,1000); // 0 significa nenhum atraso, 1000ms = 1s} public static void main (string [] args) {randomtest ran = new randomTest (); ran.timer (); // Ligue para a tarefa cronometrada}}Este artigo é reproduzido em: https://www.idaobin.com/archives/301.html