the other day , Did the subject . Find out that there are different ways to realize it .

    1. It's casual right int Exchange the numbers in the array .

    2. Is to create two arrays , One is 1-100, Another random value . Here you can set a end Variable record value length .

   
3. utilize List Provided in Colections.shuffle(), But we need to turn it into List, Attention is needed here asList Value only , But it cannot be added or deleted . Baidu .

 

1.
public class RandomArr { public static void main(String[] args) { int [] arr =
new int[100]; for(int i=0 ;i<100 ;i++) { arr[i] = i+1; } for(int i = 0 ;i<100
;i++) { int num = new Random().nextInt(100); int temp = arr[num]; arr[num] =
arr[i]; arr[i] = temp; } } }
2.
public class RandomArr { public static void main(String[] args) { int []
oldArr = new int[100]; int [] newArr = new int[100]; for(int i = 0 ;i<100 ;i++)
{ oldArr[i] = i+1; } int end = 100; for(int i = 0;i<100;i++) { int num = new
Random().nextInt(end); newArr[i] = oldArr[num]; oldArr[num] = oldArr[end-1];
end--; System.out.println("num "+num+" new "+newArr[i]); } } }
3.
String [] strArr = {"1","2","3","4","5"}; List<String> asList =
Arrays.asList(strArr); // Give Way List disorder //asList It's actually an adapter mode , It's actually an array
Collections.shuffle(asList); for (String str : strArr) {
System.out.println(str); }
 

Technology
©2019-2020 Toolsou All rights reserved,
C Language programming to find a student's grade java Realize the function of grabbing red packets Random forest R Language implementation QCustomPlot series (5)- Real time dynamic curve Software testing BUG describe use C++ I want to talk to you “ Prototype mode ” ( copy / copy constructor )JS How to operate China's longest high speed rail officially opened ! The fastest way to finish the race 30.5 hour Zimi apologizes :33W Gan charger delayed due to force majeure 2021 year 2 Chinese programming language ranking