Date: Sun, 11 Nov 2001 23:40:09 +0200 From: devotee <sixthfish@gmx.net> To: freebsd-test@freebsd.org Subject: strange rand() behaviuor Message-ID: <20011111234009.A2197@berloga.volodya.artm.org>
next in thread | raw e-mail | index | archive | help
Hi, list ! My old RSA-code failed to work in proper maner under FreeBSD 4.4. I spent 2 hours, and it seems FreeBSD version of rand() or libc or gcc or whatever have some bugs in it. Here's sample code: #include <stdio.h> int main () { int i,j; for (i=0; i<256*10; i++) { j = rand(); if (!(i%256)) printf ("i=%5d j=0x%08X j%%256=0x%02X\n",i,j,j%256); } return 0; } It just prints each 256th random number from rand(); Here's my output: bash-2.05$ gcc randtest.c -o randtest bash-2.05$ ./randtest i= 0 j=0x41C67EA6 j%256=0xA6 i= 256 j=0x32AA09A6 j%256=0xA6 i= 512 j=0x559994A6 j%256=0xA6 i= 768 j=0x5A951FA6 j%256=0xA6 i= 1024 j=0x719CAAA6 j%256=0xA6 i= 1280 j=0x4AB035A6 j%256=0xA6 i= 1536 j=0x15CFC0A6 j%256=0xA6 i= 1792 j=0x02FB4BA6 j%256=0xA6 i= 2048 j=0x4232D6A6 j%256=0xA6 i= 2304 j=0x037661A6 j%256=0xA6 As you can see, last octet of each rand value is the same !!! Under debian linux same code outputs: devotee@nerve:~$ gcc randtest.c -o randtest devotee@nerve:~$ ./randtest i= 0 j=0x6B8B4567 j%256=0x67 i= 256 j=0x5D888A08 j%256=0x08 i= 512 j=0x4695AE95 j%256=0x95 i= 768 j=0x2C06DCF3 j%256=0xF3 i= 1024 j=0x170EB52B j%256=0x2B i= 1280 j=0x22317590 j%256=0x90 i= 1536 j=0x1E1C83A1 j%256=0xA1 i= 1792 j=0x3F754C7B j%256=0x7B i= 2048 j=0x10A93FB7 j%256=0xB7 i= 2304 j=0x12130ECA j%256=0xCA (that's what i expected to see under freebsd) What's wrong ??? -- devotee, http://volodya.artm.org Hi! I'm a .signature virus! Copy me into your ~/.signature to help me spread! To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-test" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20011111234009.A2197>