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
This commit is contained in:
Przemyslaw Czerpak
2011-03-27 10:45:35 +00:00
parent 53f7911cee
commit a5fa7383a9
4 changed files with 48 additions and 0 deletions

View File

@@ -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.

View File

@@ -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 );

View File

@@ -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;
}
}

View File

@@ -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();