A source of randomness is required, and there are plenty of ways to do it: https://docs.ton.org/ko/develop/smart-contracts/guidelines/random-number-generation
A basic version of a lottery script exists here, which uses the randomize_lt
function:
https://github.com/pyAndr3w/ton-lottery-smc/blob/main/func/code.fc