Fixed bugs in acquiring lock and interruption
Added randomized test
Added pseudo-random number generation to test