- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

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?

Link Copied

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

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;

}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

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.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page