average function fromclass and random graph generator