当前位置:网站首页>【无标题】
【无标题】
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的随机数是伪随机数还是有一定的规律,是通过计算得来的)
边栏推荐
- 搬家通知!
- An article grasps the calculation and processing of date data in PostgreSQL
- Embedded development: tips and techniques -- the best practice of defensive programming with C
- TypeError: ufunc ‘bitwise_ and‘ not supported for the input types, and the inputs could not be safely
- Data mining-01
- [P4] solve the conflict between local file modification and library file
- 一个仿win10蓝屏的404页面源码
- ES6 from entry to mastery 07: Deconstruction assignment
- 测试用例管理工具
- [wrong question]mocha and railgun
猜你喜欢

Simple and easy-to-use performance testing tools recommended

BRD,MRD,PRD的区别

数据挖掘-02

leetcode刷题:动态规划09(最后一块石头的重量 II)

Data rich Computing: m.2 meets AI at the edge

静态博客搭建工具汇总

Detailed explanation of string + memory function (C language)

How to solve MySQL deep paging problem
![[paper notes] mobile robot autonomous navigation experimental platform based on deep learning](/img/6a/7f0c2b2a53332636f3172bc3b0b74d.png)
[paper notes] mobile robot autonomous navigation experimental platform based on deep learning

Leetcode58. Length of the last word
随机推荐
Redis cluster
Skillfully use stack backtracking to help you quickly locate problems
Appnium--APP自动化测试工具
Move notice!
一文读懂Plato Farm的ePLATO,以及其高溢价缘由
leetcode刷题:动态规划08(分割等和子集)
Common interface testing tools
[openvx] VX for basic use of objects_ lut
How does MySQL ensure high availability
Fourier series
Dynamic planning - 62. Different paths
Ch340 RTS DTR pin programming drives OLED
Basic knowledge of day08 redis
Monotonic stack - 739. Daily temperature
数据挖掘-01
[错题]Concatenation
数据丰富的计算:M.2在边缘遇到AI
[openvx] VX for basic use of objects_ image
Server memory failure prediction can actually do this!
Embedded development: tips and techniques -- the best practice of defensive programming with C