Intel® Makers
Intel® Edison, Intel® Joule™, Intel® Curie™, Intel® Galileo
Announcements
Welcome - This is a Peer-to-Peer Forum only. Intel has discontinued these products but you may find support from other customers on this Forum
9868 Discussions

Error when compiling random function

GMike2
Novice
1,243 Views

When ever my sketch has a line like:-

random(100,1500)

I get the error message:-

Random_Blink.pde:22:25: error: too many arguments to function 'long int random()'

any fixes for this error?

0 Kudos
3 Replies
Michael_M_Intel1
Employee
321 Views

 

The "random" function is available but has no arguments. You want to add something like the following overload (the language is really C++, not C) to the top of your file (you can delete it later when the random function is updated to follow the Arduino spec):

long int random(long int p) {

return random() % p;

}

Also randomSeed is not yet available, so comment it out for now.

GMike2
Novice
321 Views

This is only a partial solution as the Arduino random function can take one or two arguments. So based on this I added the following to my sketches:-

long int random(long int minimum, long int maximum){

return (random()+minimum) % maximum;

}

long int random(long int maximum){

return random() % maximum;

}

JFitz5
Novice
321 Views

for that first one, you want

return (random()%(maximum-minumum)+minimum)

otherwise you might end up with wraparound that could be less than minimum.

Also, both will bias towards the lower values but since this is psuedorandom and there's no seed, you might as well just return 4.

Reply