Pseudo Random Number Generator How can deterministic computers produce random numbers?…
- User
Pseudo Random Number Generator How can deterministic computers produce random numbers? And does it even need to? Turns out Classical Computers unlike Quantum Computer don’t have access to ‘Truly random numbers’. Computers need to access random numbers in order to encrypt information, perform computer simulation, do ray tracing in Computer Games, make Machine Learning happen and so much more. What we mean by random numbers here is a sequence of independent random numbers with a specified distribution. In this subtask, you will be implementing the famous ‘Middle square algorithm’ by John von Neumann to generate pseudo-random numbers. Take a 4 digit number called the seed, say 9876, now square it and extract the middle 4 digits, thus 9,75,35,376 − > 5353. And we repeat this process i.e. now take this as the four-digit number, square it and extract the middle 4 digits and so on. We highly recommended you to watch this video to get an intuition about what pseudo-random numbers are. Write a Python function pseudo rand num gen(seed, k) that generates k pseudo random numbers using the above process and uses your current system time as the seed to this function. The function returns a list containing all the k random numbers generated. Update: The middle-square algorithm needs to be implemented for a general seed with even number of digits. (Hint: A faster way to extract the middle digits is by converting the number to a string first.) In case the seed after squaring has odd no. of digits pad it with a zero in the front and then extract the middle digits. Also plot a histogram of the generated random values (after dividing by 10n where n is the no. of digits in the seed) using matplotlib
- Assistant