# Leetcode 384 - Shuffle an array

`Note:`

- How to shuffle randomly?
- For an
`array`

starting from`0`

to`len - 1`

.- First, pick an
`index`

between`[0, len - 1]`

and`swap`

with index 0. - Then, pick an
`index`

between`[1, len - 1]`

and`swap`

with index 1.

… - Pick an
`index`

between`[len - 1, len - 1]`

and`swap`

with index len - 1…

- First, pick an
- Done.

`Question:`

Given an integer array nums, design an algorithm to randomly shuffle the array. All permutations of the array should be equally likely as a result of the shuffling.

Implement the Solution class:

`Solution(int[] nums)`

Initializes the object with the integer array nums.`int[] reset()`

Resets the array to its original configuration and returns it.`int[] shuffle()`

Returns a random shuffling of the array.

`Example:`

1 | Input |

`Code:`

`O(N)`

1 | /** |