Early lotteries were done by drawing numbers, or winning tickets, from a container.
In the UK, numbers of winning Premium Bonds (which were not strictly a lottery, but very similar in approach) were generated by an electronic machine called ERNIE.
A popular type of modern lottery machine has a rotating drum with contrarotating arms inside. A number of balls, each with a possible winning number on, are dropped into the drum while it is spinning. A mechanism then extracts a pre-determined number of balls to be the winning numbers, one at a time. Machines of this type are used in 'Lotto 6-49' type games, and the UK National Lottery.
Because of the massive payoff for a successful cheat, lottery machines are subject to strict security measures. In some cases there are several machines and several sets of balls, and the combination to be used is selected at random just before the draw.