From c5a73944e27dc7566bc1ca861447439e52c875f9 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 17 May 2011 17:22:27 +0000 Subject: [PATCH] 2011-05-17 19:21 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * src/rtl/hbrandom.c ! fixed wrong random numbers being generated after: 2011-03-11 09:42 UTC+0100 Przemyslaw Czerpak this is simple revert, Przemek pls recheck/refix original issue. Values 0x????FFFF and 0x????0000 were returned from these calls: hb_randomInt( 0xFFFFFFFF ) hb_randomInt( 0xFFFFFFFE ) hb_randomInt( 0x7FFFFFFF ) under mingw32 and mingw64 (both win and linux builds) --- harbour/ChangeLog | 13 ++++++++++++- harbour/src/rtl/hbrandom.c | 13 +++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 2c014271e9..5df16db404 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,13 +16,24 @@ The license applies to all entries newer than 2009-04-28. */ +2011-05-17 19:21 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * src/rtl/hbrandom.c + ! fixed wrong random numbers being generated after: + 2011-03-11 09:42 UTC+0100 Przemyslaw Czerpak + this is simple revert, Przemek pls recheck/refix original issue. + Values 0x????FFFF and 0x????0000 were returned from these calls: + hb_randomInt( 0xFFFFFFFF ) + hb_randomInt( 0xFFFFFFFE ) + hb_randomInt( 0x7FFFFFFF ) + under mingw32 and mingw64 (both win and linux builds) + 2011-05-17 19:02 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * include/harbour.hbx * src/rtl/hbrandom.c + HB_RAND32() -> <32-bit random number> ; TOFIX: random numbers are broken under mingw 4.5.2, only high 16bits are random. - in all HB_RAND*() functions + in all HB_RAND*() functions [DONE] 2011-05-17 17:48 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * utils/hbmk2/hbmk2.prg diff --git a/harbour/src/rtl/hbrandom.c b/harbour/src/rtl/hbrandom.c index 9455b1bb8e..345e83fc53 100644 --- a/harbour/src/rtl/hbrandom.c +++ b/harbour/src/rtl/hbrandom.c @@ -141,7 +141,20 @@ double hb_random_num() } d1 = ( double ) rand(); +#ifdef __HB_THIS_FIX_BREAKS_MINGW32_64__ d2 = ( double ) RAND_MAX + 1.0; +#else + d2 = ( double ) RAND_MAX; +#if defined( __BORLANDC__ ) + /* It seems that on Windows platform there some weirdness about EPSILON value so + that a float division using an epsilon smaller than 1e-10 may be rounded. + Must dig if it's a borland lib bug or a windows problem. + */ + d2 += 0.001; +#else + d2 += DBL_EPSILON; +#endif +#endif return d1 / d2; }