Complete windows support via crude hack

Also, fix some things in tests:
1) close workspace before deleting outfile
2) call rand with the correct argument type on 32bit systems