You can use an example here: A promotion example . Then simply increase the size to a more suitable session identifier, for example 64 characters or something else. That way, you don't need to use calculations for hashing or anything else, and it is already readable.
Or without using boost-random and just using ctime and stdio.h
string getRandom(int ip) { srand(time(NULL) + ip + rand()); stringstream ss; for(int i = 0;i < 64;i++) { int i = rand() % 127; while(i < 32) i = rand() % 127; ss << char(i); } return ss.str(); }
Alternatively, without using an IP address, you can simply return rand () instead of the IP address, just make sure you generate something.
In addition, I'm certainly not a cryptographer, so use your own risk.
source share