lmms icon indicating copy to clipboard operation
lmms copied to clipboard

Improve lmms::fastRand() and use it instead of std::rand()

Open rubiefawn opened this issue 11 months ago • 2 comments

  • Combine overloads of lmms::fastRand() into one template
    • Remove RAND_MAX constant since it is not used outside lmms::fastRand() (and all places that did previously use it should have been calling lmms::fastRand() anyway)
    • This is also done to lmms::fastLog10f() for consistency, though it is not related to the goal of the PR
  • Add lmms::oneIn() convenience function to replace occurences of (fastRand() % chance == 0)
  • Replace uses of std::rand() with lmms::fastRand() for consistency
  • Replace uses of scale * lmms::fastRand() / RAND_MAX - offset with lmms::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] .ds samples 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

rubiefawn avatar Mar 02 '25 03:03 rubiefawn

Briefly tested Mallets, Spectrum Analyzer, ReverbSC, Flanger and Ogranic. I think we can (finally) merge! :tada:

bratpeki avatar Nov 01 '25 12:11 bratpeki

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.

rubiefawn avatar Dec 09 '25 20:12 rubiefawn