It does this continuously, every second, all day and night. The next second it generates thousands more possibilities. When the button is pressed, it randomly picks one result from thousands of possibilities.
Each gaming machine has a built-in computer program that randomly generates thousands of possible outcomes every second.