Utility function for random graph generation