[go: up one dir, main page]

Menu

[r104]: / libpetey / randomize.h  Maximize  Restore  History

Download this file

42 lines (32 with data), 897 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//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);
}