Random()

Why random always generate the same number? I have this code

int randomX;
int randomY;

    randomX = random(0,8);
    randomY = random(0,8);

and every time I reset the arduino the random() generate exactly the same numbers, like a patron.

Because the random function is not random. There is a randomSeed you can enter to change the sequence pattern, but that's about it. Others have made a proper random generator, so that is worth looking into.

This is a bug, not a feature. While you are working on the program it is good to know what you are getting each time. When you are ready to go prime time, you can add one of several methods of setting the seed.

One easy thing you can do, is use an EEPROM location. In setup() you can read the EEPROM, use that to set the seed, add some number to it (anything but zero!) and save that back to the EEPROM to use the next time. The best part is that you don't even need to set an initial one!

This is a bug, not a feature

No, it isn't a bug.

KeithRB:
...add some number to it (anything but zero!)...

Anything but zero, that is prime, with the resulting value clipped to a valid range...
http://forum.arduino.cc/index.php?topic=66206.msg537783#msg537783

My personal preference is to use Happy Primes.

with respect to randomseed, this issue is still open: - randomSeed should have unsigned long as parameter [imported] · Issue #575 · arduino/Arduino · GitHub -

I forgot about that bug. (But I no longer use randomSeed.)

The code available from the link above is not affected. srandom is called directly.