Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

13.9. Random 随机字符串

		
package cn.netkiller.test;

import java.util.Random;

public class QueueTest {

	public static void main(String[] args) throws InterruptedException {
		new Random().ints(10, 33, 38).forEach(System.out::println);
	}
}
		
		
		
		
36
34
34
36
37
35
34
35
34
33
		
		
		

13.9.1. 取 0-n 范围内随机数

			
    private int salt() {
        Random random = new Random();
        return random.nextInt(99999999);
    }			
			
			

13.9.2. 指定随机数范围

			
package cn.netkiller.test;

import java.util.Random;

public class RandomTest {

	public static int random(int min, int max) {
		var value = new Random().ints(min, (max + 1)).limit(1).findFirst().getAsInt();
		return value;
	}

	public static void main(String[] args) throws InterruptedException {
		System.out.println(random(10, 15));
	}
}