[bind10-dev] Query ID generation?

Michael Graff mgraff at isc.org
Fri May 21 03:34:54 UTC 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 2010-05-20 10:21 PM, Shane Kerr wrote:

> Initially this would be a very simple class, something like:
> 
> class DNSQueryIDGenerator:
>     def __init__(self):
>         pass
>     def next_qid(self):
>         return random.randint(0, 65535)

When I do this in Ruby, I find I nearly always want a random value of N
bytes long.  I have a small library I use that takes a pointer to a
location and a length, and fills it with random bytes.

Then I write specific classes like "generate a 16-bit QID" or "generate
a 128-bit random value and base64 encode it" -- I then only have one
function to test so long as the specific type functions use the class
directly.

If a class does math or any special selection on the stream of 8-bit
values returned, then I write a test just for that data type as well.

I find this works very nicely and cuts my testing down significantly.
All I need to do in the "generate a 128-bit long random string and
base64 encode it" is ensure the data comes out to the right length, for
example.  I rely on the base64 class's tests to ensure base64 works.

- --Michael
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkv1/14ACgkQ+NNi0s9NRJ1UPwCfQ9oTvcIzigbOQz0yraLVbXaC
j74AnjtJBPWLeaBFY7OMMSdjRohJ75JR
=G+5z
-----END PGP SIGNATURE-----



More information about the bind10-dev mailing list