Fix for glibc threading and portability problems

- Copied in the glibc-rand code from stdlib