ENH back-port rand_r from 4.4BSD

This function is not available on Windows and is deprecated by POSIX.
Fetched from OpenBSD:
http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/stdlib/rand.c

This reverts commit 6f737ad8d5b29a098df6b2ad0fdd1db38e801db8.