// 获得一个给定范围的随机整数
public static int getRandomNum(int smallistNum, int BiggestNum) {
Random random = new Random();
return (Math.abs(random.nextInt()) % (BiggestNum - smallistNum + 1))+ smallistNum;
}
import java.util.*;
public class Yugi{
public static void main(String[] args){
int[] arr = new int[10];
arr[0] = (int)(Math.random() * (-11));
for(int i = 1; i < arr.length - 1; i++){
int rand = (int)(Math.random() * 21) - 10;
}
arr[arr.length - 1] = (int)(Math.random() * 11);
System.out.println(Arrays.toString(arr));
}
}
https://jingyan.baidu.com/article/5225f26b46bd1ce6fa0908b3.html
用scrand试试