//provides a simple and uniform interface for random number generation...
#include <sys/timeb.h>
#include <gsl/gsl_rng.h>
#include "heapsort_tmpl.h"
long libpetey_ran_seed;
gsl_rng_type *libpetey_ran_type;
gsl_rng *libpetey_ran;
inline long seed_from_clock() {
timeb now;
ftime(&now);
return (long) now.time + ((long) now.millitm) << 7;
}
inline void ran_init(gsl_rng_type *rt) {
libpetey_ran_type=rt;
libpetey_ran=gsl_rng_alloc(libpetey_rng_type);
gsl_rng_set(libpetey_ran_type, seed_from_clock());
}
//uniform deviates:
inline double ranu() {
return gsl_rng_uniform(libpetey_ran);
}
//gaussian deviates:
inline double rang() {
return gsl_rng_gaussian(libpetey_ran);
}
inline long *randomize_vec(long n) {
double *flt;
flt=new double[n];
for (long i=0; i<n; i++) flt[i]=ranu();
delete [] flt;
return heapsort(flt, n);
}