Np.random.randn implementation

Not a problem, but purely for interest, how does this function produce exactly the right output each time I run it?
I guess this is so for all other students.
According to the numpy help the return is a purely random selection from a range.
Do Coursera doctor the seed / output from the function to guarantee the returned numbers or is it simply a ‘failing’ in the language?

The seed is set right in the template code they gave you. Search for “seed”. The call is np.random.seed.

Note that you would not normally do this in “real” code. The point of using PRNG functions is that you don’t want the values to be predictable. Here they do it just for ease of grading and comparing test results: it’s helpful for things to be predictable. They could have made the checking of results more sophisticated by making it statistical, but that’s hard work.

You can experiment for yourself: comment out the call to np.random.seed and then run the test cell a couple of times: you’ll see different results and the test cell will fail, because the results are not what it expects.

The point is that the way PRNG algorithms work is that once you set the seed to a particular value, the entire sequence after that is pre-determined. But it has whatever the statistical properties are that are required by the type of distribution you are implementing, e.g. a Normal Distribution with \mu = 0 and \sigma = 1 in this case. Normally in a real system the seed is not set or is set to something that is itself unpredictable by an attacker: e.g. some algorithm involving the input of real entropy or something like a cpu clock that changes very quickly.

Thank you Paul
I have played around with the seed values (offline) and have been surprised at just how pre-determined the results are.
A lesson I needed learn.