andy modified sampling code for graphs