rand.c

来自「CHP 3 - Real-Time Digital Signal Process」· C语言 代码 · 共 53 行

C
53
字号
// 
//  Project: Experiment 3.6.6.3 Real Time Signal Generation - Chapter 3  
//  File name: rand.c   
//
//  Description: This function generates a random number
//
//  For the book "Real Time Digital Signal Processing: 
//                Implementation and Application, 2nd Ed"
//                By Sen M. Kuo, Bob H. Lee, and Wenshun Tian
//                Publisher: John Wiley and Sons, Ltd
//
//
//  Tools used: CCS v.2.12.07
//              TMS320VC5510 DSK Rev-C
//

#define PI          0x7FFF

// Function prototype
short randNumber1(void);        
short randNumber2(void);        
void  initRand(long seed);

// Variable definition
static volatile long n;
static short a;

void initRand(long seed)
{
  n = (long)seed;
  a = 2045;
}

short randNumber1(void)          
{
  short ran;

  n = a*n + 1;
  n = n - (long)((float)(n*0x100000)/(float)0x100000);
  ran = (n+1)/0x100001;
  return (ran);
}

short randNumber2(void)          
{
  short ran;
    
  n = a*n;
  n = n&0xFFFFF000;
  ran = (short)(n>>20);
  return (ran);
}

⌨️ 快捷键说明

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