I'm updating an old ECS I wrote a couple years back, and I've written the following piece of code in order to generate a GUID:
const auto& es::EntityStore::RequestEntity()
{
    if(m_freeEntities.size() != 0)
    {
        return ec::ENTITY_ID_INVALID;
    }
    //Get the lastmost EntityID
    auto eid = m_freeEntities.back(); //an std::vector<uint64_t>
    m_freeEntities.pop_back();
    //Get the index value of the EntityID
    uint32_t idx = 0;
    idx = eid & 0XFFFFFFFF;
    //Get the version value of the EntityID
    uint32_t version = 0;
    version = ((eid >> 32) & 0xFFFFFFFF) + 1;
    //Update the metadata at idx
    m_entityMetadata.at(idx).version = version;
    //Create & return the new EntityID
    eid = version;
    eid = eid << 32 | idx;
    //an unordered_set<uint64_t>
    return *m_livingEntities.insert(eid).first;
}
However, I believe it can be written out nicer, and perhaps with less machine code generated.
HOW THE GUID WORKS
I am using a uint64_t to represent my GUID. Reading left-to-right, the first 32 bits will represent the version of the GUID, while the last 32 bits represent the index of the GUID.
The index will be used to lookup items in other arrays and vectors, so it never changes.
The version, however, is used to differentiate between an object who might have the same index as another.
When a GUID is invalidated, it is stuck onto the end of a vector. When it is reused, it's version goes up by a counter of 1.
So, if there are any game objects out there referencing ID 0 or belonging to ID 0, even though it occupies the same spot in the array because of it's index, it's GUID will be different because it's version is 1 higher than whatever GUID came before it.