Rand() with JUCE

Just ran into a weird issue when porting a noise class i wrote outside of Juce to a Juce project.

rand() was outputting the same value every time for about 1 second, and then moving on to another value.

I tried looking in my project for srand and couldn’t find anywhere that i was accidentally seeding, so was just wondering if Juce is seeding the random generator under the hood?

rand() and srand() modify global state and might lock. That’s not something you want in your audio thread. You can use an instance of JUCE: Random Class Reference instead.

1 Like