Not a lawyer, but I would be very surprised if the law that creates and regulates the lottery doesn't include a clause to make buying tickets by an algorithm illegal or something like it.
Why? The law says that you can buy tickets, and return unused ones. So just buy a bunch, scratch the winning ones, and return the rest.
There's no law which says that "if you can figure out how the lottery works, it is illegal". Their recourse is to only pull the lottery and discontinue it; they can't accuse you of fraud if you somehow figured out how to pick the right tickets.