Random.getFloat() gives me "Random is ambiguous"


#1

Hi,

C++ noob here. I'm trying to use Random.getFloat() for a noise generator within the processBlock function of my audio plugin, as per the Juce tutorial. My code is:

float noisesample = Random.nextFloat();

However, I get my friend the red squigly under "Random", telling me that it is ambiguous. I am using Microsoft Visual Studio 2015. The code is able to "find" the Random class as I have the ability to peak the definition and read the code, but it's just not happy. I'm almost tempted to use rand...

Any help greatly appreciated!

Andy.


#2

You are trying to call a non-static member function on class declaration. You need to instantiate an actual Random object, and call nextFloat() on that.

Random myRandom;

float noiseSample = myRandom.nextFloat();

Obviously it will be better to instantiate this outside of it's usage, either global, or in the class needing random numbers. :)


#3

Thanks, got it working :)