The game uses a type of pseudo-random number generator, or an RNG.
"A pseudorandwhat? Are you talking dumb again Scraf?" -Sempiternus
A pseudo-random number generator is a random number generator that starts with a base number, or a seed, and generates numbers off of that. Nothing can be truly random, and computers are no exception.
For example, say we throw Sempiternus off of a building. How many bones will be broken isn't a random number, but relies of factors such as the height of the building, how fast he approches the ground, how he lands on the ground, what he lands on, etc. Thus, this is not truly random.
Anyhow, the game generates a seed (Emerald starts at 0, Gen IV games start with a number determined by the Nintendo DS's date, time, and delay between starting the game and pressing "Continue", and games since then start with a number determined by the Nintendo DS's date, time, keys currently pressed, and other small data bites) and then "randomly" generates numbers off of that seed to determine the following:
- Individual Values
- Personality Values (Ability, Nature, Shininess, Gender)
- Wild Pokemon Species
- Lottery Number
- If an egg will be available or not in the Pokemon Day Care
Since this is not fully random, you can abuse the generator to obtain Pokemon with high IVs, shiny Pokemon, or have a winning lottery number.
Source.