From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <8516d70b903f356c737cb460bb7c6df4.axp-list@archive.invalid> X-Archive-Original-Message-ID: <199704091726.KAA06769@panda.mosberger> Date: Wed, 9 Apr 1997 10:26:47 -0700 From: David Mosberger-Tang Subject: pseudo-random number generation If you like to use something like srand48(time(0)) to initialize random number generation, you may not like the behavior you get under the current glibc. E.g., try the following program and you'll see what I mean. --- #include #include #include int main (int argc, char **argv) { int i, j; for (j = 0; j < 5; ++j) { srand48 (j); for (i = 0; i < 5; ++i) printf ("%8.6f ", drand48()); printf("\n"); } return 0; } --- This "bug" has been fixed by Uli for glibc-2.03 but in the meantime, you may want to apply the appended patch. For your convenience, I also appended a uuencoded version of the fixed erand48() object file. Erik tells me that the next Red Hat Linux/Alpha release will have this fix as well. --david <--patch--><--patch--><--patch--><--patch--><--patch--><--patch--> --- erand48_r.c~ Tue Apr 8 22:25:16 1997 +++ erand48_r.c Tue Apr 8 22:25:29 1997 @@ -35,9 +35,9 @@ its fractional part so the resulting FP number is [0.0,1.0). */ #if USHRT_MAX == 65535 - *result = ((double) xsubi[2] / (1ULL << 48) + + *result = ((double) xsubi[2] / (1ULL << 16) + (double) xsubi[1] / (1ULL << 32) + - (double) xsubi[0] / (1ULL << 16)); + (double) xsubi[0] / (1ULL << 48)); #else # error Unsupported size of short int #endif <--erand48.o--><--erand48.o--><--erand48.o--><--erand48.o--><--erand48.o--> begin 644 erand48_r.o M?T5,1@(!`0````````````$`)I`!`````````````````````````#@7```` M`````````$```````$``#``)````NR<``+TCT/_>(P``7K<(`#ZU$`!>M0D$ M$$8*!%)&``!]IP!`6VL``+HG``"](R<``.@!E"!!`M$@1```0J0!,2!$P@)! M2"``7K0@`+Z-```]I,L7[5L``"&,:Q1A60%4($$"T2!$``!"I`$Q($3"`D%( M(`!>M"``OHT``#VDS!?M6P``(8QL%(%9`=$@10``(:0",2!%P0(B2"``/K0@ M`+Z-``!=I,$7[5L``$*-810J6`L4;%D+%&%9``3_1P``:IT#`.##'P3_1Q\$ M_T?__Q\@``!>IP@`/J40`%ZE'A3&0P&`^FL``````````)(9"P,````````` M``$```"1``````````0```#@"0``8`````$`````````"0`````````````` M`````````````````````,`!``````````(``````````````````!`+```` M````(`L`````````%0```````&`5``````````````````#`%0`````````` M``````````````````!\````_____P`&``30____````````````````,``` M`/__________`````!X`&@````````````$```!+$`D`__________\-```` MP`(PCP``````````20D``$5`-H\```````````$```!%0#:/```````````4 M```````XCP``````````-@``````.(\``````````$@``````#B/```````` M``"*```````XCP``````````HP``````.(\``````````.X``````#B/```` M```````U`0`````XCP``````````A0$`````.(\``````````*,!`````#B/ M``````````#%`0`````XCP``````````X@$`````.(\``````````/X!```` M`#B/```````````0`@`````XCP``````````(P(`````.(\``````````#L" M`````#B/``````````!H`@`````XCP``````````@P(`````.(\````````` M`)\"`````#B/``````````#``@`````XCP``````````S`(`````.(\````` M`````-8"`````#B/``````````#A`@`````XCP``````````!P,`````.(\` M`````````"\#`````#B/``````````!>`P`````XCP``````````<@,````` M.(\``````````(0#`````#B/``````````"6`P`````XCP``````````J`,` M````.(\``````````+L#`````#B/``````````#/`P`````XCP`````````` MX0,`````.(\``````````/,#`````#B/```````````)!``````XCP`````` M````&P0`````.(\``````````"T$`````#B/``````````!`!``````XCP`` M````````5`0`````.(\``````````&H$`````#B/``````````!]!``````X MCP``````````D00`````.(\``````````*4$`````#B/``````````"]!``` M```XCP``````````T@0`````.(\``````````.4$`````#B/```````````3 M!0`````XCP``````````'@4`````.(\``````````"<%`````#B/```````` M```P!0`````XCP``````````.04`````.(\``````````$(%`````#B/```` M``````!+!0`````XCP``````````5`4`````.(\``````````%T%`````#B/ M``````````!F!0`````XCP``````````P@4`````.(\``````````,\%```` M`#B/``````````#@8````` M.(\``````````(4&`````#B/``````````"2!@`````XCP``````````GP8` M````.(\``````````*P&`````#B/``````````"Z!@`````XCP`````````` MQ@8`````.(\``````````-,&`````#B/``````````#@!@`````XCP`````` M````[08`````.(\``````````/H&`````#B/```````````%!P`````XCP`` M````````$`<`````.(\``````````!L'`````#B/```````````D!P`````X MCP``````````+@<`````.(\``````````#@'`````#B/``````````!$!P`` M```XCP``````````3P<`````.(\``````````%@'`````#B/``````````!A M!P`````XCP``````````:@<`````.(\``````````'0'`````#B/```````` M``!_!P`````XCP``````````B`<`````.(\``````````)('`````#B/```` M``````";!P`````XCP``````````I`<`````.(\``````````*\'`````#B/ M``````````"Z!P`````XCP``````````Q@<`````.(\``````````,\'```` M`#B/``````````#9!P`````XCP``````````X@<`````.(\``````````.P' M`````#B/``````````#T!P`````XCP``````````_P<`````.(\````````` M``P(`````#B/```````````7"``````XCP``````````)`@`````.(\````` M`````"\(`````#B/```````````\"``````XCP``````````1P@`````.(\` M`````````%0(`````#B/``````````!B"``````XCP``````````D@@````` M.(\``````````)T(`````#B/``````````"H"``````XCP``````````!0D` M````.(\``````````%L)``!%T`$```````````!@"0``1A```!P````````` M:@D``$70`0`@`````````&\)``!%\`$`-`````````!T"0``16`"`+P````` M````>0D``$70`@#``````````'X)``!%8`(`Q`````````"#"0``1=`"`-`` M````````B`D``$4``@#H`````````&`)``!(P`<```````````"-"0``14`R MCPD`````````'@D`````-(\1`````````"L)`````#2/"@`````````Z"0`` M```TCP``````````F@D``$7P__\``````````*D)``!%\/__``````````"Z M"0``PO/__P@`````````OPD``,+S__\0`````````,0)``#"\___```````` M``#)"0``0O'__P@`````````SPD``$7P__\```````````$```!(```````` M`(4```````````````!E"!L;VYG(&1O=6)L93IT,3@]5]T.G0Q`'5?8VAA