当前位置:网站首页>【无标题】
【无标题】
2022-07-28 03:54:00 【只会写BUG的程序猿..】
生成不随机二维数组##
加粗样式`在这里插Random r = new Random();
int index = 0;
for(int i=0;i<arr.length;i++) {
for(int j=0;j<arr[i].length;j++) {
index = r.nextInt(arrs.length-1);
arr[i][j] = arrs[index];
arrs[index] = arrs[index]+arrs[arrs.length-1-i];
arrs[arrs.length-1-i] = arrs[index]-arrs[arrs.length-1-i];
arrs[index] = arrs[index]-arrs[arrs.length-1-i];
}
}入代码片`
将生成的随机数用index记录,在arrs数组中将index所代表的元素放到最后一位,
-1:数组从零开始
-i:随着i的自增,生成随机数的个数,(-1-i)达到将生成数删除,达到不重复目的
1注意:arrs的元素个数一定要大于arr的元素个数(建议最小十倍),不然不保证不重复(java的随机数是伪随机数还是有一定的规律,是通过计算得来的)
边栏推荐
- TypeError: ufunc ‘bitwise_ and‘ not supported for the input types, and the inputs could not be safely
- 高等数学(第七版)同济大学 习题3-4 个人解答(后8题)
- Recursion and non recursion are used to calculate the nth Fibonacci number respectively
- 搬家通知!
- Basic knowledge of day08 redis
- 高等数学(第七版)同济大学 习题3-4 个人解答(前8题)
- 面试必备杀技:SQL查询专项训练!
- In depth introduction to sap ui5 fileuploader control - why do you need a hidden iframe trial
- ES6 from entry to mastery 07: Deconstruction assignment
- C language: realize the exchange of two numbers without creating temporary variables
猜你喜欢

Msgan is used for pattern search of multiple image synthesis to generate confrontation Network -- to solve the problem of pattern collapse

How does MySQL ensure high availability

Lightpicture - exquisite drawing bed system

Notes on writing questions in sword finger offer

ES6 from getting started to mastering 08: extended object functions

8000 word explanation of OBSA principle and application practice

C语言:不创建临时变量实现两数交换

R notes mice

高等数学(第七版)同济大学 习题3-4 个人解答(前8题)

MySQL Basics (create, manage, add, delete, and modify tables)
随机推荐
In depth introduction to sap ui5 fileuploader control - why do you need a hidden iframe trial
Dynamic programming - 416. Segmentation and subsets
Redis cluster
【OPENVX】对象基本使用之vx_matrix
Differences among BRD, MRD and PRD
Interface automation test, complete introduction
Build an "industrial brain" and improve the park's operation, management and service capabilities with "digitalization"!
做自动化测试,你后悔了吗?
Leetcode 0141. circular linked list - three solutions
C语言:不创建临时变量实现两数交换
【OPENVX】对象基本使用之vx_image
LeetCode_409_最长回文串
ES6 from entry to mastery 07: Deconstruction assignment
【OPENVX】对象基本使用之vx_lut
input 上传文件并回显 FileReader并限制选择文件时的类型
[P4] check the differences between the two historical versions of the library file
SAP UI5 FileUploader 控件深入介绍 - 为什么需要一个隐藏的 iframe 试读版
Msgan is used for pattern search of multiple image synthesis to generate confrontation Network -- to solve the problem of pattern collapse
【OPENVX】对象基本使用之vx_distribution
Summary and interpretation of CONDA virtual environment