I'm using random() to generate time lengths based on a potentiometer position.
The code all works fine if I were to enter intrinsic figures into the random, such as:
timeRate = random(1.63, 59.12);
However if I set the values inside the random as floating variables such as this, it only spits out 0 (when the pot is set to the lower half), or 1 (when the pot is set to it's higher half)
timeRate = random(timeMin, timeMax);
I've checked through the serial monitor, and the timeMin and timeMax figures are coming through accurately. I've tried entering the numbers those floating vars are displaying directly into the random and it works fine.
I've no idea what's causing this and the whole thing kind of relies on this working. Any thoughts?
Hey guys, sorry, turns out I was being an idiot and had added an additional line earlier that I'd forgotten about which was basically rounding down the figures to 0 or 1.
As for the random, thanks for pointing it out it's limited to integers, good to know.
As it happens, part of the problem I'd been facing was due to passing the wrong data to it.
The variable inputs as the from/to figures are generated by multiplying an integer by a float. Works fine now.