Random juce assertion?

My code doesn't pass this juce assertion. What could be the cause?

int Random::nextInt (const int maxValue) noexcept
    jassert (maxValue > 0);
    return (int) ((((unsigned int) nextInt()) * (uint64) maxValue) >> 32);

I declare the random instance in a class owned by another class and this assertion is passed until i send something in the constructor to the owned class, (looks to me like that should be completely unrelated).

I'm probably lacking some basic c++ syntax understanding.


If your debugger already stopped at the assert, it should also tell you the value of maxValue. And it is less than 0 otherwise the assert would have passed.

Reason 1: the calling parameter is not initiallized - the assert appears random

Reason 2:  the value exceeds 2^15, the boundary of signed short int (I hope this is still valid nowadays, when bits became cheap). Numbers with the first bit set are considered to be negative.


Thank you!

Yeah my debugger stops there, maxValue is 0 so it "triggers" the assert. 0 means it's not reason 2, right?

I initialize my Random like this:


   ScopedPointer<Random> mRand = new Random();

It all works just fine, until I change my code to pass some (completely unrelated) variable, to the constructor of this class, from the owner class. Why could that be?

If it is reason 1, I don't understand how to fix it. I simply use it like this:

number1 = mRand->nextInt(30);



Nevermind, the variable I sent was totally related and wasn't initialized properly, I'm an idiot and again, thank you!!



...happens to the best of us ;-)