Quote Originally Posted by boops boops View Post
I don't know why you are concerned about the number of leading zeroes. A random number should average half way in value between the minimum and the maximum. For example, random numbers from 1 to 1000 should average 500, not 50. Shorter numbers are increasingly rare: in the range 1 to 1000 there are only 49 numbers less than 50 but 950 above it.

In binary terms, the average value of random binary numbers from 0 to 1nnn.... should be 01nnn...., not something with a lot of leading zeroes. The chance of any given number cropping up in a 4097-byte random array is once in 2^(4097*8). The chance of a randomized byte array having 3900 zero bytes in a row is once in 2^(3900*8). I bet you would wear out dunfiddlin's Cray trying to find even one of those. BB

BB
Did you try the test code I posted? The results I found seemed to indicate that your method is skewed to the high end of the range, which is what I suspected. Maybe it is an error with how I tested.

When I saw that your method used the larger size only I suspected this would be the result. Since there was only a 1 in 256 chance that the high order byte would be 0, as well as any other, it seemed logical that this would be the result.