refactor code to separate func for question1
add func to generate random directed graph