Basic Markov Chain Algorithm So I have a file(story.dat) with a randomly generated story like:
&quot;Sleeping in his car was never the plan but sometimes things don't work out as planned. This...&quot;
It will print out each word and the corresponding word to it like so:
0.&quot;It: was,
1.&quot;Pepsi-Cola.&quot;: He,
2.&quot;This: is,
3./: 50.,
4.50: /,
5.50.: I,
6.A: long,
7.All: that,
8.He: didn't,knew,had,
9.I: think,had,
10.I'd: love,
11.I'm: certain,
12.It: was,
13.Or: at,
14.She: knew,
15.Sleeping: in, ...

And then it prints the story like so:

have a cup of everything. The inside was ten, and a little strange,
but he was either exhausted of days ago. It was supposed to hear from
you today and fondling over it. He knew what made the last option is
to make a year ago. It was supposed to make this case, was in months.
The third is the sun. He knew...

Here's the code:
// #include files
namespace Randomiser
{
    std::mt19937 generator{ static_cast&lt;std::mt19937::result_type&gt;(std::time(nullptr)) };
}
int getRandomNumber(int min, int max)
{
    std::uniform_int_distribution&lt;int&gt; rand{ min, max };
    return rand(Randomiser::generator);
}

void markovIt(const std::map&lt;std::string, std::vector&lt;std::string&gt;&gt;&amp; m)
{
    std::string temp{};
    std::vector&lt;std::string&gt; possibilities{};
    std::string next{};
    
    int i{ 0 };
    int randomNumber{ getRandomNumber(0, m.size()) };
    for (const auto&amp; n : m)
    {
        if (i == randomNumber)
        {
            temp = n.first;
        }
        ++i;
    }

    auto found{ m.find(temp) };
    i = 0;
    while(found != m.end())
    {
        if (i == 255)
            break;

        possibilities = found-&gt;second;
        next = possibilities.at(getRandomNumber(0, possibilities.size() - 1));
        
        std::cout &lt;&lt; temp &lt;&lt; &quot; &quot;;
        temp = next;
        
        found = m.find(temp);
        ++i;
    }
}

int main()
{
    std::ifstream wordStream{ &quot;story.dat&quot; };
    std::string fWord;
    std::string sWord;
    std::vector&lt;std::string&gt; temp;
    std::map&lt;std::string, std::vector&lt;std::string&gt;&gt; gram{};
    int i{ 0 };
    while(wordStream)
    {
        wordStream &gt;&gt; fWord;
        if (i != 0)
            gram[sWord].push_back(fWord);
        wordStream &gt;&gt; sWord;
        gram[fWord].push_back(sWord);
        if (i == 0)
            i++;
    }

    i =  0;
    for (const auto&amp; n : gram)
    {
        std::cout &lt;&lt; i &lt;&lt; &quot;.&quot; &lt;&lt; n.first &lt;&lt; &quot;: &quot;;
        for (const auto&amp; key : n.second)
            std::cout &lt;&lt; key &lt;&lt; &quot;,&quot;;
        std::cout &lt;&lt; '\n';
        ++i;
    }

    markovIt(gram);
    std::cout &lt;&lt; '\n';

    return 0;
}

The implementation feels awful and I believe it could be optimised alot further. I'm just not sure where to take it.
Use std::random_device instead of time()
Stay within C++, and use a real random device to seed the generator, like so:
std::random_device rd;
std::mt19937 generator{rd()};

Consider turning Randomiser into an anonymous namespace
Does this namespace need a name? If only getRandomNumber() uses Randomiser::generator, and it's in the same source file, you can make it an anonynous namespace instead, just omit &quot;Randomiser&quot;.
Be consistent with types
Avoid mixing types like int and size_t. It might seem to work fine, but it is easy for errors to happen this way. Before changing types, consider that sometimes you don't really need to specify a type explicitly, and can instead use template&lt;&gt; or auto. For example:
template&lt;typename T&gt;
auto getRandomNumber(T min, T max)
{
    std::uniform_int_distribution&lt;T&gt; rand{ min, max };
    return rand(Randomiser::generator);
}

However, you will now get some compiler errors, because you were actually calling getRandomNumber() with min and max having different types, like in:
int randomNumber{ getRandomNumber(0, m.size()) };

This is actually a good thing, the compiler is telling you something fishy is going on. In fact, m.size() returns a size_t, which can be bigger than what an int can hold on most 64-bit platforms, as well as being unsigned instead of signed. Considering that min is always 0 in your code, I would instead write:
template&lt;typename T&gt;
auto getRandomNumber(T max) {
    std::uniform_int_distribution&lt;T&gt; rand{ 0, max };
    return rand(Randomiser::generator);
}

...

auto randomNumber = getRandomNumber(m.size());

Note that you probably meant getRandomNumber(m.size() - 1) here. This brings me to:
Consider writing a getRandomElement() function
You actually use the random numbers to pick random elements out of containers. So write a function to do exactly that:
template&lt;typename T&gt;
static auto &amp;getRandomElement(const T &amp;container)
{
    std::uniform_int_distribution&lt;size_t&gt; rand{ 0, container.size() - 1 };
    return *std::next(std::begin(container), rand(Randomiser::generator));
}

Simplifying markovIt()
Now that we have the above, we can simplify markovIt() greatly. It can be rewritten as:
void markovIt(const std::map&lt;std::string, std::vector&lt;std::string&gt;&gt;&amp; m)
{
    // Get the initial word
    auto word = getRandomElement(m).first;

    for (int i = 0; i &lt; 255; ++i)
    {
        std::cout &lt;&lt; word &lt;&lt; &quot; &quot;;

        // Find the entry in m that matches word
        auto entry = m.find(word);
        if (entry == m.end())
            break;

        // Select a random word from the list of possibilities
        word = getRandomElement(entry-&gt;second);
    }
}

Move special cases out of loops if possible
While loading story.dat, you use the variable i do determine if you need to push back the first word. You can move that special case outside of the loop. The compiler will probably do this for you even if you don't, but it also cleans up the code if you do so in this case:
wordStream &gt;&gt; fword;
wordStream &gt;&gt; sWord;
gram[fWord].push_back[sWord];

while(wordStream)
{
    wordStream &gt;&gt; fWord;
    gram[sWord].push_back(fWord);
    wordStream &gt;&gt; sWord;
    gram[fWord].push_back(sWord);
}

However, why read two words in each loop iteration? You can rewrite this to:
wordStream &gt;&gt; fWord;

while(wordStream)
{
    wordStream &gt;&gt; sWord;
    gram[fWord].push_back(sWord);
    fWord = sWord;
}

Move more functionality into functions
You are doing too much inside main(). Move more functionality into functions, and keep main() as high-level as possible. For example:
static auto load_gram(const std::string &amp;filename)
{
    std::map&lt;std::string, std::vector&lt;std::string&gt;&gt; gram{};
    std::ifstream wordStream{ filename };

    // load the data into gram here
    ...

    return gram;
}

int main(int argc, char *argv[])
{
    auto gram = load_gram(&quot;story.dat&quot;);
    markovIt(gram);
}