From a5fa7383a9406bd8147bc58fa0af4cfd8e515940 Mon Sep 17 00:00:00 2001 From: Przemyslaw Czerpak Date: Sun, 27 Mar 2011 10:45:35 +0000 Subject: [PATCH] 2011-03-27 12:45 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/include/hbapi.h * harbour/src/rtl/hbrandom.c added new C functions which fills memory block with random values: void hb_random_block( void * data, HB_SIZE len ) this function should be used with "good enough" random generator so in the future it may be changed to use internally sth different then rand(). * harbour/src/vm/thread.c * pacified minor warning --- harbour/ChangeLog | 12 ++++++++++++ harbour/include/hbapi.h | 1 + harbour/src/rtl/hbrandom.c | 33 +++++++++++++++++++++++++++++++++ harbour/src/vm/thread.c | 2 ++ 4 files changed, 48 insertions(+) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index b4936df8d8..3d7115f435 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -16,6 +16,18 @@ The license applies to all entries newer than 2009-04-28. */ +2011-03-27 12:45 UTC+0200 Przemyslaw Czerpak (druzus/at/priv.onet.pl) + * harbour/include/hbapi.h + * harbour/src/rtl/hbrandom.c + added new C functions which fills memory block with random values: + void hb_random_block( void * data, HB_SIZE len ) + this function should be used with "good enough" random generator + so in the future it may be changed to use internally sth different + then rand(). + + * harbour/src/vm/thread.c + * pacified minor warning + 2011-03-26 00:13 UTC-0800 Pritpal Bedi (bedipritpal@hotmail.com) + contrib/hbqt/hbqtsql.hbc ! Miss from prev commit. diff --git a/harbour/include/hbapi.h b/harbour/include/hbapi.h index 950371d269..e5e7845373 100644 --- a/harbour/include/hbapi.h +++ b/harbour/include/hbapi.h @@ -968,6 +968,7 @@ extern HB_EXPORT char * hb_numToStr( char * szBuf, HB_SIZE nSize, HB_MAXINT n extern HB_EXPORT double hb_numRound( double dResult, int iDec ); /* round a number to a specific number of digits */ extern HB_EXPORT double hb_numInt( double dNum ); /* take the integer part of the number */ extern HB_EXPORT double hb_random_num( void ); +extern HB_EXPORT void hb_random_block( void * data, HB_SIZE len ); extern HB_EXPORT double hb_numDecConv( double dNum, int iDec ); extern HB_EXPORT double hb_numExpConv( double dNum, int iDec ); extern HB_EXPORT void hb_strtohex( const char * pSource, HB_SIZE size, char * pDest ); diff --git a/harbour/src/rtl/hbrandom.c b/harbour/src/rtl/hbrandom.c index 959e1961c2..e2c1bb23da 100644 --- a/harbour/src/rtl/hbrandom.c +++ b/harbour/src/rtl/hbrandom.c @@ -140,3 +140,36 @@ double hb_random_num() 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(); + else + v >>= 8; + *ptr++ = ( HB_BYTE ) v; + } +} diff --git a/harbour/src/vm/thread.c b/harbour/src/vm/thread.c index 7b9b5d5413..218d9442cf 100644 --- a/harbour/src/vm/thread.c +++ b/harbour/src/vm/thread.c @@ -1068,7 +1068,9 @@ PHB_THREADSTATE hb_threadStateClone( HB_ULONG ulAttr, PHB_ITEM pParams ) PHB_THREADSTATE pThread = NULL; pThread = hb_threadStateNew(); +#if defined( HB_MT_VM ) if( hb_stackId() != NULL ) +#endif { pThread->pszCDP = hb_cdpID(); pThread->pszLang = hb_langID();