I am looking for a way to uniformly choose values in GF(2^M) between two bounds.
GF(2^M) is a Galois Field - See GF(4) as defined on this page - http://www.math.umbc.edu/~campbell/Math413Spr09/Notes/12-13_Finite_Fields.html
From a technical, non-math perspective, this is most similar to CRC operations.
For example:
ulong gf2step( ulong x, int bits, ulong p )
{
x = x << 1; // "multiply" by x
if ( x >= (1 << bits)) x = x ^ p;
return x;
}
Expanding the example from below:
12 is '1100 '1100 shifted left by 1 becomes `11000. Since bit 4 is set, xor with `10011 (p). Next is `1011 or 11.
Similarly,
9 is '1001 '1001 shifted left by 1 becomes `10010. Since bit 4 is set, xor with `10011 (p). Next is `0001.
My obvious method is to start with the integer exponents corresponding to the bounds, pick a random exponent between those and generate the value from that.
However, this has two problems --
1. Given arbitrary bounds, I can't find the corresponding integer exponent..
2. This will be repeated many, many times, so I am concerned about exponentiation speed.
Example:
int gf2random( ulong low, ulong high, ulong p);
gf2random( 12, 13, 19) should return evenly from the set {12, 11,5,10,7,14,15, 13}
gf2random( 9, 1, 19) should return either 9 or 1
I can step the values in GF(2^M) fairly easily - but I'm not sure how to avoid overshooting the upper bound.
Does it simplify the problem if the low bound was always '1' ?