Note, There is a big difference between doing a transactionon a database and "using transactions"
MySQL does not (really) support transactions, so I'll continue to talk about "queries"
It depends on what you want to do with a table.
A lock is only used to make sure nobody else can change the records untill you are finished doing your queries, and you release the lock.
This also means that if you take a long time to finish your queries, everybody else will have to wait. Not good in a web environment.
Locking is good if you want to insert a lot of records at once. It can be much faster with a lock than without a lock.
Locking should not be used to generate unique numbers (as you originally asked)
But it can be used to mark a record as "in use"
You'd lock the table for writing, choose a record that's not in use, mark it as "used" and release the lock. That way you can be sure nobody else can choose that same record and use it.