You will need a technique for creating multiple concurrent requests for processing against the same record that is locked using FOR UPDATE.
One option is to use the @future annotation to queue up multiple concurrent requests that will retrieve a single record using FOR UPDATE in the SOQL call. If you can get these methods executing for long enough you will start getting UNABLE_TO_LOCK_ROW errors as transactions timeout waiting for the exclusive lock.
From anonymous apex you can make several calls to the future method to get them running at the same time.
You will need to create some form of busy operation to keep the record locked for more than 5 seconds (but less than 10 seconds). This could be a simple a for loop that counts from 0 to some very large number. You will need to experiment with the large number to get the required timing.