Instructions
Walk east on Route 121 to get to Lilycove City. Head to the department store in the middle of the city.
Approach the department store front door. If this is your first time here, your rival, either Brendan or May, challenges you to a fight. Defeat your rival and go inside the store.
Approach the desk on the front floor. Save your game. If you want to try to "cheat" the lottery game, wait for one in-game day.
Talk to the lady behind the counter. She gives you a lottery number. If all five digits perfectly match one of your Pokemon's IDs, you win the Master Ball as a prize.
Reset the game and talk to the lady again if the numbers do not perfectly match. You can normally only get one lottery ticket per day, but if you saved before you talked to the lady that day, it is possible to reset the game and get a new lottery number until you win the prize.