3 Replies Latest reply on Oct 14, 2013 12:28 AM by joe_fitz

    Error when compiling random function

    Grumpy_Mike

      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?

        • 1. Re: Error when compiling random function
          McCool


          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.

          1 of 1 people found this helpful
          • 2. Re: Error when compiling random function
            Grumpy_Mike

            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;

            }

            • 3. Re: Error when compiling random function
              joe_fitz

              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.

              1 of 1 people found this helpful