The bytes are apparently not evenly distributed.
I put together some code to sample the .NET Guids and plot the distribution:
First of all the test code, this creates one million Guids and counts the number of different values for each byte in the byte array. It outputs it all into a matrix that I plot in Scilab.
int[,] counter = new int[16, 256];
for (int i = 0; i < 1000000; i++)
{
var g = Guid.NewGuid();
var bytes = g.ToByteArray();
for (int idx = 0; idx < 16; idx++)
{
counter[idx, bytes[idx]]++;
}
}
StringBuilder sb = new StringBuilder();
sb.AppendLine("x = [");
for (int idx = 0; idx < 16; idx++)
{
for (int b = 0; b < 256; b++)
{
sb.Append(counter[idx, b]);
if (idx != 255)
{
sb.Append(" ");
}
}
if (idx != 15)
{
sb.AppendLine(";");
}
}
sb.AppendLine("]");
File.WriteAllText("plot.sce", sb.ToString());
Here are the distributions, the graphs plot the number of each distinct value for each of the positions in the byte array:
The value distribution for the positions 0-6 in the byte array:
The value distribution for the position 7 in the byte array:
The value distribution for the position 8 in the byte array:
The value distribution for the positions 9-15 in the byte array:
For byte positions 0-6 and 9-15 the distribution of values seems to be even, but for byte position 7 and 8 the distribution is fairly limited.
That is, for the guid (with the beginning of the byte positions below, note strange ordering)
{1369ea05-b9f9-408b-ac7c-7ebd0f35d562}
1 1 1 1 1 1
3 2 1 0 5 4 7 6 8 9 0 1 2 3 4 5
The position 7 can take the values from 64 (0x40) to 79 (0x4F).
The position 8 can take the values from 128 (0x80) to 191 (0xBF).
The rest of the bytes are evenly distributed.
Note: The tests was run on .NET4 on a 32 bit Windows 7 machine.
Lesson: don't assume stuff, test.
Answer: To use the .NET Guids for calculating your load balancing, you can use any part except the positions marked 7 and 8 in the Guid above.
Question: Does anybody know WHY the distribution is not evenly spread?