I am looking for solution to pick number randomly from an integer array.
For example I have an array new int[]{1,2,3}, how can I pick a number randomly?
package io.github.baijifeilong.tmp;
import java.util.concurrent.ThreadLocalRandom;
import java.util.stream.Stream;
/**
* Created by BaiJiFeiLong@gmail.com at 2019/1/3 下午7:34
*/
public class Bar {
public static void main(String[] args) {
Stream.generate(() -> null).limit(10).forEach($ -> {
System.out.println(new String[]{"hello", "world"}[ThreadLocalRandom.current().nextInt(2)]);
});
}
}