So, I’m trying to add to my random sequencer a way to optionally fix the random seed via CV.
I’ve been taking a look at the features in random.hpp & random.cpp, naïvely thinking I could figure out how it’s seeded, and I must say I have zero clue how any of all that machinery ticks.
I gave a try using std::mt19937 in a test module and it seems to work. I tried seeding it a fixed seed and flipping a coin every sample to see what happens, the CPU cost is obviously very high, but doing it only 1000x per second the cpu cost is negligible, and in practice I’ll call it 10 times per second at most.
I guess I have two questions:
Am I missing a simple way to force Rack’s PRNG seed?
Any non-obvious drawback to using the standard library’s in my case? I don’t need the random distribution to pick numbers more than a few times per second, or the randomness to be of high quality, but I need it to be deterministic when used on the same machine.
The rack one looks like it uses time of day as a seed. Should be good enough, yes?
void init() {
struct timeval tv;
gettimeofday(&tv, NULL);
xoroshiro128plus_state[0] = tv.tv_sec;
xoroshiro128plus_state[1] = tv.tv_usec;
// Generate a few times to fix the fact that the time is not a uniform u64
for (int i = 0; i < 10; i++) {
xoroshiro128plus_next();
}
}
That’s not really what I’m asking! I don’t really understand the implications of monkeying around with this,
I’d like a sanity check on how to best proceed.
If I do something dangerous/expensive etc. and submit it to the library, I can’t change it without breaking people’s patches.
Thanks! Means my test implementation was a safe way to go about it. Since controlling the random seed controls the melody, people would be seriously annoyed if I changed implementations later.
And also doing a bunch of dry runs to warm it up, cf. how VCV does it.
I left it to run (without an external seed) on my Darius sequencer overnight, and it follows the expected normal distribution, unlike mt19937, which would skew to a side.