I am creating a smart contract which simulates a lottery game: users purchase tickets from a fixed pool of tickets, and at the end, a random ticket number is drawn for the winner. I am now concerned with the process of selecting the random ticket number which is the winning ticket.
I was reading this post: How can I securely generate a random number in my smart contract?
and I still do not understand why I can't simply generate a random number in the range
1 - amount of tickets and assign that to be the winning tickets, using the equivalent of:
randomNum = 1 + (int)(Math.random() * amount_of_tickets);
This sounds very trivial, but I do not see how it would be unfair or how it could be manipulated since every ticket would have an equal chance of being selected. It was also suggested that I should use the hash of the chain head in this computation, again I do not understand why this would be beneficial or necessary.