Readme.txt The bug appears when the first call to mpz_urandomb() is made. If the integer is exported to an array of unsigned short, an extra nibble is inserted ahead of the legitimate data. The extra nibble caused problems with latter array processing. I fixed this in my prgram by doing a call to mpz_urandomb() with a scratch variable. But I thought you folk might want to look at it. Here's a brief view of the screen output This is the mpz_t value. zN1 = 0x203c28cbbbeeb323a64c2a8206459 And the value I got from mpz_export(). n1 = 0x0203C28CBBBEEB323A64C2A820 Notice the there is an extra leading nibble. Here's the report data you requested. gmp-4.2.2, prepacked, built and run on a cygwin system. $ . ./configure $ make $ make install gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125) CYGWIN_NT-5.1 BO-DT014 1.5.25(0.156/4/2) 2007-12-14 19:21 i686 Cygwin core2-pc-cygwin Here is the test file that demonstrates the bug /****************************************************/ // extranibble.c // //Random Number Generator Error Demonstration // // To: gmp-bugs@swox.com // #include #include #include #include #include typedef unsigned long UL; typedef unsigned short US; mpz_t zN1; mpz_t zN2; mpz_t zMod; gmp_randstate_t rState; int main( int argc, char** argv ) { int i; int sMod, sN2, sN1; US *n1, *n2, *mod; mpz_init2(zN1, 2048); mpz_init2(zN2, 2048); mpz_init2(zMod, 2048); gmp_randinit_mt(rState); gmp_randseed_ui(rState, 9243650); mpz_urandomb(zN1, rState, 2048); // This one gets the extra nibble mpz_urandomb(zN2, rState, 2048); // These two don't mpz_urandomb(zMod, rState, 2048); mod = (US *)mpz_export(NULL, &sMod, 1, 2, -1, 0, zMod); n2 = (US *)mpz_export(NULL, &sN2, 1, 2, -1, 0, zN2); n1 = (US *)mpz_export(NULL, &sN1, 1, 2, -1, 0, zN1); gmp_printf ("\n\r\n\r zN1 = %Z#x", zN1); fprintf(stdout, "\n\r n1[%i] = 0x", sN1); for (i = 0; i < sN1; i++) { fprintf(stdout, "%04X", n1[i]); } gmp_printf ("\n\r\n\r zN2 = %Z#x", zN2); fprintf(stdout, "\n\r n2[%i] = 0x", sN2); for (i = 0; i < sN2; i++) { fprintf(stdout, "%04X", n2[i]); } gmp_printf ("\n\n\r zMod = %Z#x", zMod); fprintf(stdout, "\n\rmod[%i] = 0x", sMod); for (i = 0; i < sMod; i++) { fprintf(stdout, "%04X", mod[i]); } exit(0); } /******************************************************/ And the Makefile... CC := gcc CFLAGS := -c extranibble: extranibble.o Makefile $(CC) -o extranibble extranibble.o -lgmp cp extranibble.exe /usr/local/bin/extranibble extranibble.o:extranibble.c Makefile $(CC) $(CFLAGS) $(INC) extranibble.c -o extranibble.o ########################################### Good luck and happy hunting. Jim