Mercurial > hg > audiodb
diff sample.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 | d9dba57becd4 |
children |
line wrap: on
line diff
--- a/sample.cpp Tue Jul 01 22:17:33 2008 +0000 +++ b/sample.cpp Wed Jul 02 13:53:23 2008 +0000 @@ -35,7 +35,7 @@ return c; } -unsigned audioDB::random_track(unsigned *propTable, unsigned total, gsl_rng *rng) { +unsigned audioDB::random_track(unsigned *propTable, unsigned total) { /* FIXME: make this O(1) by using the alias-rejection method, or some other sensible method of sampling from a discrete distribution. */ @@ -56,18 +56,6 @@ void audioDB::sample(const char *dbName) { initTables(dbName, 0); - gsl_rng *rng = gsl_rng_alloc(gsl_rng_mt19937); - - /* FIXME: in Real Life we'll want to initialize the RNG using - /dev/random or the current time or something, like this: - - unsigned int seed; - int fd = open("/dev/urandom", O_RDONLY); - read(fd, &seed, 4); - - gsl_rng_set(rng, seed); - */ - // build track offset table (FIXME: cut'n'pasted from query.cpp) off_t *trackOffsetTable = new off_t[dbH->numFiles]; unsigned cumTrack=0; @@ -104,8 +92,8 @@ double sumlogdist = 0; for (unsigned int i = 0; i < nsamples;) { - unsigned track1 = random_track(propTable, total, rng); - unsigned track2 = random_track(propTable, total, rng); + unsigned track1 = random_track(propTable, total); + unsigned track2 = random_track(propTable, total); if(track1 == track2) continue;