I do not ask if they are truly random. I just wanted to know if two users can simultaneously get to the page, can they get the same random number? I think if I run this on a multi-core server, will I get the same randon number, how long is it due to synchronization or for some other reasons?
public static class SBackend
{
static Random randObj = null;
public static void init()
{
randObj = new Random((int)DateTime.Now.ToBinary());
runFirstTime();
}
public static long getRandomId()
{
long randNum = (long)randObj.Next() << 33;
randNum |= (uint)randObj.Next() << 2;
randNum |= (uint)randObj.Next() & 3;
return randNum;
}
}
user34537
source
share