1
+ /*
2
+ Shuffle a set of numbers without duplicates.
3
+
4
+ Example:
5
+
6
+ // Init an array with set 1, 2, and 3.
7
+ int[] nums = {1,2,3};
8
+ Solution solution = new Solution(nums);
9
+
10
+ // Shuffle the array [1,2,3] and return its result. Any permutation of [1,2,3] must equally likely to be returned.
11
+ solution.shuffle();
12
+
13
+ // Resets the array back to its original configuration [1,2,3].
14
+ solution.reset();
15
+
16
+ // Returns the random shuffling of array [1,2,3].
17
+ solution.shuffle();
18
+
19
+ */
20
+ package main
21
+ type Solution struct {
22
+ arr []int
23
+ }
24
+
25
+
26
+ func Constructor (nums []int )Solution {
27
+ return Solution {arr :nums }
28
+ }
29
+
30
+
31
+ /** Resets the array to its original configuration and return it. */
32
+ func (this * Solution )Reset () []int {
33
+ return this .arr
34
+ }
35
+
36
+
37
+ /** Returns a random shuffling of the array. */
38
+ func (this * Solution )Shuffle () []int {
39
+ tmp := make ([]int ,len (this .arr ))
40
+ copy (tmp ,this .arr )
41
+ for i := 0 ;i < len (tmp );i ++ {
42
+ r := rand .Intn (len (tmp ))
43
+ tmp [i ],tmp [r ]= tmp [r ],tmp [i ]
44
+ }
45
+ return tmp
46
+ }