put code into functions; set up weighted random number generator