Blog - Single Post

GUID (128 bits) into an int (32 bits)

  • Thursday, March 29, 2012
  • by hbopuri

To achieve Random number generator with GUID

internal static int GetIntegerGUID()
        {
            byte[] seed = Guid.NewGuid().ToByteArray();
            for (int i = 0; i < 3; i++)
            {
                seed[i] ^= seed[i + 4];
                seed[i] ^= seed[i + 8];
                seed[i] ^= seed[i + 12];
            }
            int convertedGUID = BitConverter.ToInt32(seed, 0);
            convertedGUID = Convert.ToInt32(convertedGUID.ToString().Replace('-', '0').Substring(0, 10));
            return convertedGUID;
        }