Refactored so that the generated random network can be reused.