Below is the implementation in ASP.NET for creating session ids (I've paraphrased).
edit (the RNG is shared):
static _randgen = new RNGCryptoServiceProvider();
string GetSessionId()
{
var buffer = new byte [15];
//fill the buffer with random bytes
randgen.GetBytes(buffer);
//turn the bytes into a string of letters and numbers (no unsafe chars)
string encoding = Encode(buffer);
return encoding;
}
The documentation on RNGCryptoServiceProvider.GetBytes
says it is thread safe, however it's not clear what kind of thread safety that means. Does it simply guarantee no deadlocks or does it guarantee two threads will get different values? Is it possible for there to be a race condition where 2 requests would pull the same session id?