Implement custom PRNG. (Fixes #1214)

I adapted the linked script from #1214 and put the (shortened) code into library.js. I the switch ENABLE_SRAND as well, to switch this change on and off. By default it's off.
It seems a bit long and doesn't fit library.js. Should I put it in a different file?