From 5553c16493b86d8f5847045e9354ed6a57b08d06 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 21 May 2011 10:42:24 +0000 Subject: [PATCH] 2011-05-21 12:41 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) * include/harbour.hbx * src/rtl/hbrandom.c * HB_RANDOMMAX() -> HB_RANDOMINTMAX() ; TOFIX: now broken under mingw in all places where HB_RANDOMINT() is potentially called with larger than HB_RANDOMINTMAX() value. This will be impossible f.e. in RANDOM() CT function. * src/rtl/hbrandom.c * src/rtl/hbrand.c + hb_random_block() changed to use ARC4 backend. * examples/httpsrv/modules/showcounter.prg % hb_ntos() --- harbour/ChangeLog | 15 ++++++++ .../examples/httpsrv/modules/showcounter.prg | 2 +- harbour/include/harbour.hbx | 2 +- harbour/src/rtl/hbrand.c | 5 +++ harbour/src/rtl/hbrandom.c | 38 +------------------ 5 files changed, 23 insertions(+), 39 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 5088ab5a1b..e4256de13b 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,21 @@ The license applies to all entries newer than 2009-04-28. */ +2011-05-21 12:41 UTC+0200 Viktor Szakats (harbour.01 syenar.hu) + * include/harbour.hbx + * src/rtl/hbrandom.c + * HB_RANDOMMAX() -> HB_RANDOMINTMAX() + ; TOFIX: now broken under mingw in all places where HB_RANDOMINT() + is potentially called with larger than HB_RANDOMINTMAX() + value. This will be impossible f.e. in RANDOM() CT function. + + * src/rtl/hbrandom.c + * src/rtl/hbrand.c + + hb_random_block() changed to use ARC4 backend. + + * examples/httpsrv/modules/showcounter.prg + % hb_ntos() + 2011-05-21 12:02 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/src/rtl/valtoexp.prg ! fixed typo in recent modifications causing RTE in HB_VALTOEXP() diff --git a/harbour/examples/httpsrv/modules/showcounter.prg b/harbour/examples/httpsrv/modules/showcounter.prg index ed6c9c86ae..b97cb5c38e 100644 --- a/harbour/examples/httpsrv/modules/showcounter.prg +++ b/harbour/examples/httpsrv/modules/showcounter.prg @@ -80,7 +80,7 @@ FUNCTION HRBMAIN() IF !Empty( cHtml ) uhttpd_SetHeader( "Content-Type", "image/gif" ) uhttpd_SetHeader( "Pragma", "no-cache" ) - uhttpd_SetHeader( "Content-Disposition", "inline; filename=counter" + LTrim( Str( hb_randomint( 100 ) ) ) + ".gif" ) + uhttpd_SetHeader( "Content-Disposition", "inline; filename=counter" + hb_ntos( hb_randomint( 100 ) ) + ".gif" ) uhttpd_Write( cHtml ) ELSE uhttpd_SetHeader( "Content-Type", "text/html" ) diff --git a/harbour/include/harbour.hbx b/harbour/include/harbour.hbx index 0509652ffa..891ecf6977 100644 --- a/harbour/include/harbour.hbx +++ b/harbour/include/harbour.hbx @@ -694,8 +694,8 @@ DYNAMIC HB_PVALUE DYNAMIC HB_RAND32 DYNAMIC HB_RANDOM DYNAMIC HB_RANDOMINT +DYNAMIC HB_RANDOMINTMAX DYNAMIC HB_RANDOMSEED -DYNAMIC HB_RANDOMMAX DYNAMIC HB_RASCAN DYNAMIC HB_RAT DYNAMIC HB_RDDGETTEMPALIAS diff --git a/harbour/src/rtl/hbrand.c b/harbour/src/rtl/hbrand.c index 7bb874b6e7..505973208d 100644 --- a/harbour/src/rtl/hbrand.c +++ b/harbour/src/rtl/hbrand.c @@ -58,3 +58,8 @@ HB_FUNC( HB_RAND32 ) /* returns an integer between 0 and 0xFFFFFFFF (inclusive) { hb_retnint( hb_arc4random() ); } + +void hb_random_block( void * data, HB_SIZE len ) +{ + hb_arc4random_buf( data, len ); +} diff --git a/harbour/src/rtl/hbrandom.c b/harbour/src/rtl/hbrandom.c index 4094a8b0ba..7e8d541473 100644 --- a/harbour/src/rtl/hbrandom.c +++ b/harbour/src/rtl/hbrandom.c @@ -124,7 +124,7 @@ HB_FUNC( HB_RANDOMSEED ) s_fInit = HB_TRUE; } -HB_FUNC( HB_RANDOMMAX ) +HB_FUNC( HB_RANDOMINTMAX ) { #if RAND_MAX > HB_VMLONG_MAX hb_retnd( RAND_MAX ); @@ -149,39 +149,3 @@ double hb_random_num( void ) return d1 / d2; } - -void hb_random_block( void * data, HB_SIZE len ) -{ - HB_BYTE * ptr = ( HB_BYTE * ) data; - int i, n, v; - - if( ! s_fInit ) - { - srand( ( unsigned ) hb_dateMilliSeconds() ); - s_fInit = HB_TRUE; - } - -#if RAND_MAX >= HB_U32_MAX - n = 4; -#elif RAND_MAX >= UINT24_MAX - n = 3; -#elif RAND_MAX >= HB_U16_MAX - n = 2; -#else - n = 1; -#endif - i = 1; - v = 0; - - while( len-- ) - { - if( --i == 0 ) - { - v = rand(); - i = n; - } - else - v >>= 8; - *ptr++ = ( HB_BYTE ) v; - } -}