comparison common.cpp @ 279:dee55886eca0 sampling

make the RNG a part of the audioDB object. Easier to deal with memory discipline and initialization (though note the FIXME comment in audioDB::initTables()). Also initialize the RNG from the current time. A mature implementation would use a proper source of entropy...
author mas01cr
date Wed, 02 Jul 2008 13:53:23 +0000
parents 4dcb09f5fe85
children d9a88cfd4ab6
comparison
equal deleted inserted replaced
278:d9dba57becd4 279:dee55886eca0
68 } 68 }
69 exit(1); 69 exit(1);
70 } 70 }
71 } 71 }
72 72
73 void audioDB::initRNG() {
74 rng = gsl_rng_alloc(gsl_rng_mt19937);
75 if(!rng) {
76 error("could not allocate Random Number Generator");
77 }
78 /* FIXME: maybe we should use a real source of entropy? */
79 gsl_rng_set(rng, time(NULL));
80 }
81
73 void audioDB::initDBHeader(const char* dbName) { 82 void audioDB::initDBHeader(const char* dbName) {
74 if ((dbfid = open(dbName, forWrite ? O_RDWR : O_RDONLY)) < 0) { 83 if ((dbfid = open(dbName, forWrite ? O_RDWR : O_RDONLY)) < 0) {
75 error("Can't open database file", dbName, "open"); 84 error("Can't open database file", dbName, "open");
76 } 85 }
77 86
177 } 186 }
178 } 187 }
179 } 188 }
180 189
181 void audioDB::initTables(const char* dbName, const char* inFile = 0) { 190 void audioDB::initTables(const char* dbName, const char* inFile = 0) {
191 /* FIXME: initRNG() really logically belongs in the audioDB
192 contructor. However, there are of the order of four constructors
193 at the moment, and more to come from API implementation. Given
194 that duplication, I think this is the least worst place to put
195 it; the assumption is that nothing which doesn't look at a
196 database will need an RNG. -- CSR, 2008-07-02 */
197 initRNG();
182 initDBHeader(dbName); 198 initDBHeader(dbName);
183 initInputFile(inFile); 199 initInputFile(inFile);
184 } 200 }