提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
移位和缩放的随机整数。
import java.security.SecureRandom; // program uses class SecureRandom public class Main {/**来 自 时代Java - nowjava.com**/ public static void main(String[] args) { // randomNumbers object will produce secure random numbers SecureRandom randomNumbers = new SecureRandom(); // loop 20 times for (int counter = 1; counter <= 20; counter++) { // pick random integer from 1 to 6 int face = 1 + randomNumbers.nextInt(6); /* 来 自 时 代 J a v a 公 众 号 - nowjava.com*/ System.out.printf("%d ", face); // display generated value