In arduino, it’s random(min, max), but I was typing in the Spark Build and it highlighted just rand. Is that the built-in function? I saw some examples using function like:
int random(int max) {
return random(0, max);
}
int random(int minVal, int maxVal)
{
// int rand(void); included by default from newlib
return rand() % (maxVal-minVal+1) + minVal;
}
I wonder why do we have wrap the rand() function that way?
@metaculus, having @mdma on the Spark Team rocks! Until that change makes it to production, you can look at @kennethlimcp's repo for another topic (spark_wiring_random.cpp & .h) for files you can use.
Thanks, but I can’t take the credit for this one, it was @zachary who did the lion’s share of the work here. I just added some unit tests.
Equally exciting is that the firmware can how get a random seed from the cloud (from a cryptographically secure source) so sequences start from a very randomized seed.
as @ScruffR says, the error report says that you are calling this on line 1 of the blink.cpp which is not likely to work. Did you mean to call it in setup() or loop() or some other function instead?
Ah, didn’t know this had to be inside of a function, originally had the following just to isolate the issue. Looks like throwing it inside setup or loop works fine.