in a declaration he would like to use a randomly generated number
header
#ifndef __OBLAST_H__
#define __OBLAST_H__
class Oblast
{
private:
int pocetSten = 0;
long nahodneCislo;
public:
Oblast(int);
Oblast();
void vystup();
int nahoda();
};
#endif
You can do that, but since you call random() before seeding the random function, pocetSten will have the exact same value every time the program runs. Using analogRead() in the constructor to seed the random function may be problematic. In general, it's not a good idea to try to use the hardware in a constructor.
Instead of trying to use the hardware in the constructor, I recommend considering the common approach of creating a begin function, that you call from setup(). That way, you know the hardware has been correctly initialized before you try to use it.
The random number data does not necessarily have to be popped from the analog pin. I do not require any accuracy. It keeps me any number in the range. I tried to use both the input for randomSeed and the integer value even so it still gave me the same output
Passing a fixed value to randomSeed() will still result in random() providing the same pseudo-random number sequence every time the program is run. randomSeed() just sets your position in the sequence. If you always start from the same position, then you always get the same sequence.
I can't say whether that is a problem for your application. For example, if you were making a machine for gambling, it would be an issue because the player would know they can just unplug the machine and then they will get the same results every time.
Although there are other ways of getting a random input for randomSeed() (this being my preference), I think they will all involve use of the hardware.
I once did a command line game. Where two characters, a player and a computer, fought each other. Now I'm trying to make this game for Arduino. When, for example, the lives of a post will be represented by an LED. And this is the only thing I'm stuck with. Because the original game was able to create arenas of random shapes that gave different classes of characters the advantage of magic, etc.