adding a random stream and refactoring the code to support that