当前位置:网站首页>【无标题】
【无标题】
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的随机数是伪随机数还是有一定的规律,是通过计算得来的)
边栏推荐
- Leetcode58. 最后一个单词的长度
- Detailed explanation of string + memory function (C language)
- 构建“产业大脑”,以“数字化”提升园区运营管理及服务能力!
- Collection | 0 basic open source data visualization platform flyfish large screen development guide
- LeetCode_ 409_ Longest palindrome string
- Common weak network testing tools
- My creation anniversary
- Appnium--APP自动化测试工具
- Error no matching function for call to 'std:: exception:: exception (const char [15])' problem solving
- Prefix-Tuning: Optimizing Continuous Prompts for Generation
猜你喜欢

Basic knowledge of day08 redis

8000 word explanation of OBSA principle and application practice

Summary of static blog building tools

In December, the PMP Exam adopted the new syllabus for the first time. How to learn?

TypeError: ufunc ‘bitwise_and‘ not supported for the input types, and the inputs could not be safely

【LeetCode】34、在排序数组中查找元素的第一个和最后一个位置

Differences among BRD, MRD and PRD

Capacity expansion and reduction of RBD block storage device (VI)
![[leetcode] 34. Find the first and last positions of elements in the sorted array](/img/f0/3eaa33fa7b13abe5f27b136239507d.png)
[leetcode] 34. Find the first and last positions of elements in the sorted array

LabVIEW loads and uses custom symbols in tree control projects
随机推荐
Monotonous stack -- 42. Receiving rain -- a difficult problem that big factories must know
[P4] check the differences between the two historical versions of the library file
leetcode刷题:动态规划09(最后一块石头的重量 II)
Appnium -- app automated test tool
Responsive high-end website template source code Gallery material resource download platform source code
Leetcode brush question: dynamic planning 09 (weight of the last stone II)
搬家通知!
Simple and easy-to-use performance testing tools recommended
[leetcode] 34. Find the first and last positions of elements in the sorted array
R notes mice
Prefix-Tuning: Optimizing Continuous Prompts for Generation
【OPENVX】对象基本使用之vx_lut
C语言:求一个整数存储在内存中的二进制中1的个数
Super nice PHP program source code of nteam official website
Common weak network testing tools
Do you regret doing automated testing?
Weekly recommended short video: how to correctly understand the word "lean"?
LeetCode_409_最长回文串
[wrong question]
VBA reads the create document of SQL in batches to create tables