⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 initrand.c

📁 微软的基于HMM的人脸识别原代码, 非常经典的说
💻 C
字号:
/*M///////////////////////////////////////////////////////////////////////////////////////
//
//                      INTEL CORPORATION PROPRIETARY INFORMATION
//         This software is supplied under the terms of a license agreement or
//         nondisclosure agreement with Intel Corporation and may not be copied
//         or disclosed except in accordance with the terms of that agreement.
//               Copyright (c) 1999 Intel Corporation. All Rights Reserved.
//
//    RCS:
//       $Source:   initrand.c$
//       $Revision: 00.00.05$
//      Purpose:
//      Contents:
//      Authors:
//        Sergey Oblomov
//
//M*/

#include "ats.h"

/*F///////////////////////////////////////////////////////////////////////////////////////
//    Name:    atsInitRandom
//    Purpose:
//      Initialazing by randomize value
//    Context:
//    Parameters:
//      Min - minimal bound
//      Max - maximum bound
//    Returns:
//    Notes:
//F*/
double atsInitRandom( double Min, double Max )
{
  static int flag = 0;
  if( flag == 0 )
  {
    srand( (unsigned)time( NULL ) );
    flag = 1;
  } /* if */

  return (double)rand() / RAND_MAX * (Max - Min) + Min;
} /* atsInitRandom */


/*F///////////////////////////////////////////////////////////////////////////////////////
//    Name:    ats1bInitRandom
//    Purpose:
//      Initialazing unsigned char array by randomize value
//    Context:
//    Parameters:
//      Min  - minimal bound
//      Max  - maximum bound
//      pDst - destination array
//      lLen - size of array
//    Returns:
//    Notes:
//F*/
void ats1bInitRandom( double Min, double Max, unsigned char* pDst, long lLen )
{
  /* Some variables */
  int i;

  assert( pDst != NULL );
  assert( lLen > 0 );
  /* Init */
  for( i = 0; i < lLen; i++ ) pDst[i] = (unsigned char)atsInitRandom( Min,Max );

} /* ats1bInitRandom */


/*F///////////////////////////////////////////////////////////////////////////////////////
//    Name:    ats1cInitRandom
//    Purpose:
//      Initialazing unsigned char array by randomize value
//    Context:
//    Parameters:
//      Min  - minimal bound
//      Max  - maximum bound
//      pDst - destination array
//      lLen - size of array
//    Returns:
//    Notes:
//F*/
void ats1cInitRandom( double Min, double Max, char* pDst, long lLen )
{
  /* Some variables */
  int i;

  assert( pDst != NULL );
  assert( lLen > 0 );
  /* Init */
  for( i = 0; i < lLen; i++ ) pDst[i] = (unsigned char)atsInitRandom( Min,Max );

} /* ats1cInitRandom */


/*F///////////////////////////////////////////////////////////////////////////////////////
//    Name:    ats1iInitRandom
//    Purpose:
//      Initialazing unsigned char array by randomize value
//    Context:
//    Parameters:
//      Min  - minimal bound
//      Max  - maximum bound
//      pDst - destination array
//      lLen - size of array
//    Returns:
//    Notes:
//F*/
void ats1iInitRandom( double Min, double Max, int* pDst, long lLen )
{
  /* Some variables */
  int i;

  assert( pDst != NULL );
  assert( lLen > 0 );
  /* Init */
  for( i = 0; i < lLen; i++ ) pDst[i] = (int)atsInitRandom( Min,Max );

} /* ats1iInitRandom */


/*F///////////////////////////////////////////////////////////////////////////////////////
//    Name:    ats1flInitRandom
//    Purpose:
//      Initialazing unsigned char array by randomize value
//    Context:
//    Parameters:
//      Min  - minimal bound
//      Max  - maximum bound
//      pDst - destination array
//      lLen - size of array
//    Returns:
//    Notes:
//F*/
void ats1flInitRandom( double Min, double Max, float* pDst, long lLen )
{
  /* Some variables */
  int   i;

  assert( pDst != NULL );
  assert( lLen > 1 );

  /* Init */
  for( i = 0; i < lLen; i++ )
  {
    pDst[i] = (float)atsInitRandom( Min, Max );
  } /* for */

} /* ats1flInitGradRandom */

/*F///////////////////////////////////////////////////////////////////////////////////////
//    Name:    ats1flInitGradRandom
//    Purpose:
//      Initialazing unsigned char array by randomize value
//    Context:
//    Parameters:
//      Min  - minimal bound
//      Max  - maximum bound
//      pDst - destination array
//      lLen - size of array
//    Returns:
//    Notes:
//F*/
void ats1flInitGradRandom( double Min, double Max, float* pDst, long lLen )
{
  /* Some variables */
  int   i;
  float flStep;

  assert( pDst != NULL );
  assert( lLen > 1 );

  flStep = (float)(Max - Min) / (lLen - 1);

  /* Init */
  pDst[0] = (float)Min;
  pDst[lLen - 1] = (float)Max;
  for( i = 1; i < lLen - 1; i++ )
  {
    pDst[i] = (float)atsInitRandom( pDst[i - 1] + 0.1 * flStep,
                             flStep * (i + 1) - 0.1 * flStep );
    assert( pDst[i] > pDst[i - 1] );
  } /* for */

} /* ats1flInitGradRandom */

/* End of file. */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -