package com.zy.asrs.utils;
|
|
import java.util.Random;
|
|
public class NumUtils {
|
// public static void main(String[] args) {
|
//
|
//
|
//
|
// int randomInt = ;
|
// System.out.println("随机整数: " + randomInt);
|
//
|
//
|
// int randomIntInRange = ; // 0 到 99
|
// System.out.println("0 到 99 之间的随机整数: " + randomIntInRange);
|
//
|
//
|
// double randomDouble = random.nextDouble();
|
// System.out.println("0 到 1 之间的随机浮点数: " + randomDouble);
|
// }
|
|
public static void main(String[] args) {
|
// 获取一个 0 到 1 之间的随机浮点数
|
double randomDouble = Math.random();
|
System.out.println("0 到 1 之间的随机浮点数: " + randomDouble);
|
|
// 获取一个指定范围内的随机整数,例如 [0, 100) 的随机数
|
int randomIntInRange = (int) (Math.random() * 100); // 0 到 99
|
System.out.println("0 到 99 之间的随机整数: " + randomIntInRange);
|
}
|
|
public static double GetRandomDouble(){
|
// 获取一个 0 到 1 之间的随机浮点数
|
return Math.random();
|
}
|
|
public static double GetRandomIntInRange(){
|
// 获取一个指定范围内的随机整数,例如 [0, 100) 的随机数
|
return (int) (Math.random() * 100);
|
}
|
|
public static double GetRandomInt(){
|
Random random = new Random();
|
// 获取一个随机整数
|
return random.nextInt();
|
}
|
|
public static double GetRandomIntInRange(Integer integer){
|
Random random = new Random();
|
// 获取一个指定范围内的随机整数,例如 [0, 100) 的随机数
|
return random.nextInt(integer);
|
}
|
//
|
// public static double GetRandomDouble(){
|
// Random random = new Random();
|
// // 获取一个 0 到 1 之间的随机浮点数
|
// return random.nextDouble();
|
// }
|
|
|
}
|