### 2 Tutorial 7.2: Randomising the order of the training items

In this exercise, we will randomise the order of the training items at each epoch.

#### 2.1 Shuffling a list

First we focus on writing the `shuffle`

function that can randomly shuffle a list.

```
shuffle :: TFGen −> [a] −> [a]
```

The first argument is a TFGen generator. You may need to use it to add randomness while shuffling. There are many different ways to implement this function. If you cannot find one, use the following hints. Although they can lead you to a simple solution, it is not an optimal one. You also can explore some good solutions here.

##### 2.1.1 Hints

- 1.
- Implement a recursive function which takes a TFGen generator and an integer
`n`

as inputs and produces a list of`n`

random Word32.`randomList :: TFGen −> Int −> [Word32]`

- 2.
- Complete
`shuffle’`

. This function can shuffle a list using a random stream of Word32 and modular arithmetic.`shuffle’ :: [Word32] −> [a] −> [a]`

...

shuffle’ (x:xs) ls = let (firsts, rest) = splitAt ((fromIntegral x ‘mod‘ length ls) + 1) ls

in ... - 3.
- Complete
`shuffle`

using the supporting functions you have just implemented.

#### 2.2 Shuffling the training set at each epoch

Modify your `trainNetwork`

function to shuffle the order of the training items at each epoch. Test your
new function and compare the results.