90-100 반복의 임의 수를 생성합니다.
public class randomtest {public static void main (String [] args) { / * * Math.random () 메소드 기본값은 이중 유형으로 기본적으로 int * / int x = (int)로 캐스트되어야합니다 (Math.random () * (100-90+1) +90); // (max-min+1)+min = min-max system.out.println (x); }}90-100 비 반복 랜덤 숫자를 생성합니다.
import java.util.hashset; import java.util.random; import java.util.set; public class randomtest {public static void main (String args []) {int max = 100; // 최대 값 int min = 90; // 최소 값 int count = max-min; // 랜덤 번호 random random random = new random (); set <integer> set = new Hashset <> (); // 해시 세트 컨테이너는 (set.size () <count) {// 저장된 요소 수 int x = random.nextInt (max-min+1)+min; // 임의의 숫자 set을 만듭니다 .add (x); // (int i : set) {// foreach traversal 컨테이너 요소 시스템 .out.println (i);}}}}에 대한 무작위 숫자를 해시 세트 컨테이너}에 추가합니다.90-100 반복의 임의 수가 초당 생성됩니다.
import java.util.random; import java.util.timer; import java.util.timertask; public class randomtest {void timer () {타이머 타이머 = new Timer (); // timer.schedule (new Timertask () {public void run () {// runnable 인터페이스를 구현하는 timertask run method = new random (); int x = random.nextint (100-90+1) +90; // (max-min+1)+min = min to max // int x = random.nextint (100)%(100)%(100)%(100)%(100)% System.out.println (x);}}, 0,1000); // 0은 지연이 없음을 의미합니다. Ran.Timer (); // 시간이 정한 작업을 호출}}이 기사는 https://www.idaobin.com/archives/301.html에서 재현됩니다