How to use random_r

I couldn't find any clear example of how to use the GNU random_r function in a multithreaded program when I was trying to fix up a simulation today, so here's an example (error checking omitted):

#include <pthread.h>
#include <stdlib.h>
#define NTHREADS 4
#define PRNG_BUFSZ 32
...