Add cleanup to test state.
Fix random number generation & clean code.

ResourceManager now has a random number generator, which can be used for
the C++ style of generating random numbers.