Mercurial > hg > audiodb
diff 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 |
line wrap: on
line diff
--- a/common.cpp Tue Jul 01 22:17:33 2008 +0000 +++ b/common.cpp Wed Jul 02 13:53:23 2008 +0000 @@ -70,6 +70,15 @@ } } +void audioDB::initRNG() { + rng = gsl_rng_alloc(gsl_rng_mt19937); + if(!rng) { + error("could not allocate Random Number Generator"); + } + /* FIXME: maybe we should use a real source of entropy? */ + gsl_rng_set(rng, time(NULL)); +} + void audioDB::initDBHeader(const char* dbName) { if ((dbfid = open(dbName, forWrite ? O_RDWR : O_RDONLY)) < 0) { error("Can't open database file", dbName, "open"); @@ -179,6 +188,13 @@ } void audioDB::initTables(const char* dbName, const char* inFile = 0) { + /* FIXME: initRNG() really logically belongs in the audioDB + contructor. However, there are of the order of four constructors + at the moment, and more to come from API implementation. Given + that duplication, I think this is the least worst place to put + it; the assumption is that nothing which doesn't look at a + database will need an RNG. -- CSR, 2008-07-02 */ + initRNG(); initDBHeader(dbName); initInputFile(inFile); }