lmms
lmms copied to clipboard
Improve lmms::fastRand() and use it instead of std::rand()
- Combine overloads of
lmms::fastRand()into one template- Remove
RAND_MAXconstant since it is not used outsidelmms::fastRand()(and all places that did previously use it should have been callinglmms::fastRand()anyway) - This is also done to
lmms::fastLog10f()for consistency, though it is not related to the goal of the PR
- Remove
- Add
lmms::oneIn()convenience function to replace occurences of(fastRand() % chance == 0) - Replace uses of
std::rand()withlmms::fastRand()for consistency - Replace uses of
scale * lmms::fastRand() / RAND_MAX - offsetwithlmms::fastRand(min, max)
// Old
int x = static_cast<int>(10.0f * rand() / RAND_MAX - 3.0f);
// New
int x = fastRand(-3, 7);
Testing
- [x] Triple Oscillator noise sounds the same
- [x] Organic randomize preset button works
- [x] Multiple Peak Controllers can coexist
- [x] Sfxr randomize preset button works
- [x] SID plugin sounds the same
- [x] Vibed plugin sounds the same
- [x]
.dssamples with noise sound the same - [x] Undo/redo doesn't instantly explode
- [x] Mixer channel color randomization works
- [x] Clip color randomization works
- [x] Track color randomization works
Briefly tested Mallets, Spectrum Analyzer, ReverbSC, Flanger and Ogranic. I think we can (finally) merge! :tada:
Now that this has an approval from a dev with write access, I plan to merge this PR on 2026-01-08, provided no issues are found in the meantime. If anyone else would like to review this PR, please do so before that date.