Really basic terrain generator This is my first attempt at writing a c++ program, so bear with me. I tried to use as many methods as I learned in about a week-long period.

#include &lt;iostream&gt;
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;


void generator(char tree, char water, char land)
{
    const char tileList[] = {tree, water, land};
    int tileIndex = rand() % 3;

    std::cout &lt;&lt; tileList[tileIndex] &lt;&lt; " ";
}


int main()
{
    srand(time(NULL));

    while(true)
    {
        generator('T', '~', '.');
    }
}


I took out comments to improve code readability. What can be improved? What needs to be changed?
This won't compile:


void generator(char tree, char water, char land);
// ...
generator("T", "~", ".");



Because generator takes 3 chars, and you're giving it const char* instead.

Of course that's easy to fix, just make the params chars:

generator('T', '~', '.');




It would be better if the generator generated, instead of printing.
It's to preserve the single responsibility principle.
Like this:

char generator(char tree, char water, char land)
{
    const char tileList[] = {tree, water, land};
    int tileIndex = rand() % 3;
    return tileList[tileIndex];
}

int main()
{
    srand(time(NULL));

    while(true)
    {
        std::cout &lt;&lt; generator('T', '~', '.') &lt;&lt; " ";
    }
}




Of course the loop will never end... Are you ok with that?



Taking 3 chars as possible tiles doesn't seem too flexible. How about making it work with arbitrary number of tiles? Something like this:

char generator(const char * tiles, int len)
{
    int index = rand() % len;
    return tiles[index];
}

int main()
{
    srand(time(NULL));

    const char * tiles = "T~.";
    int len = strlen(tiles);

    while(true)
    {
        std::cout &lt;&lt; generator(tiles, len) &lt;&lt; " ";
    }
}