Strengthening pseudo random number generator and adding tests to verify its behavior.

Closes #5454 and #5578