use wide apis explictly
stop using rand() which is blocking and horrid use the random header
use strings and ensure file handle gets closed