Thursday 16 June 2022

Chapter 24 // Exercise 10 - Principles & Practice Using C++

In this exercise I am using Visual Studio 2019 and a modified version of the std_lib_facilities header found here.

Chapter 24 // Exercise 10

How random is your default_random_engine? Write a program that takes two integers n and d as inputs and calls randint(n) d times, recording the result. Output the number of draws for each of [0:n] and "eyeball" how similar the counts are. Try with low values for n and with low values for d to see if drawing only a few random numbers causes obvious biases.


I used some of the code on pg 915/916 but didn't add the normal distribution bit. Originally, the std_lib_facilities file did not seed the default random engine so it wasn't random at all. I changed that a while back and now it uses the pc time as a seed so it's almost always different. On this run, it looked pretty random? That said I just did a 5 draws with a max of 5 over and over and it started to seem pretty suspicious after while. But for a single number I need now and then, it's fine.


No comments:

Post a Comment