diff common.cpp @ 284:cacad987d785

Really finish with the sampling branch, this time merging all of it, yes, even the last revision. (The last revision was one that seeded the RNG with the current time, which is helpful when trying to get multiple independent-ish samples from the same database...)
author mas01cr
date Mon, 07 Jul 2008 08:57:06 +0000
parents 4dcb09f5fe85
children d9a88cfd4ab6
line wrap: on
line diff
--- a/common.cpp	Thu Jul 03 08:50:57 2008 +0000
+++ b/common.cpp	Mon Jul 07 08:57:06 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);
 }