removed a couple of instance of errno clobbering
rethinking randomization and reentrance, adding more tests