1 // 2 def swap(arr:Array[Int],a:Int,b:Int)={ 3 val tmp = arr(a) 4 arr(a)=arr(b) 5 arr(b)=tmp 6 } 7 def shuffle(arr:Array[Int])={ 8 val t = new Random() 9 for(i <- (1 to arr.length-1).toArray.reverse) 10 swap(arr,i,t.nextInt(i+1)) 11 }
时间: 2024-10-08 23:40:34