RPG help:random battles&Leveling

Ok im working on an RPG and i need help with Random battles(where you are running around and you get into a random battle)and i also need help with Leveling up abd that having effect on stats and health! if you have any links or tutorials plz post thnx!