home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / os / msdos / programm / 12453 < prev    next >
Encoding:
Text File  |  1993-01-25  |  1.2 KB  |  46 lines

  1. Xref: sparky comp.os.msdos.programmer:12453 comp.os.msdos.misc:7195 comp.programming:3597
  2. Newsgroups: comp.os.msdos.programmer,comp.os.msdos.misc,comp.programming
  3. Path: sparky!uunet!grebyn!daily!bittware
  4. From: bittware@grebyn.com (Bittware)
  5. Subject: Re: Random number function (SUPPLIED)
  6. Message-ID: <1993Jan26.021158.10416@grebyn.com>
  7. Organization: Grebyn Timesharing
  8. References: <1jv5udINNl5u@duncan.cs.utk.edu> <1k1gh3INN9r5@darkstar.UCSC.EDU>
  9. Date: Tue, 26 Jan 1993 02:11:58 GMT
  10. Lines: 34
  11.  
  12. I coded this up from an article I think in EDN, by an engineer at 
  13. Tektronix.  The code in the article was in some DSP assembler, and I
  14. converted it to C (isn't that backwards??).  Anyway, it works.  I tested
  15. it on a DSP32c output to a D/A and to a spectrum analyzer.
  16.  
  17. -----BEGIN RAN32.C-----
  18.  
  19. #include <math.h>
  20.  
  21. /* generate 32-bit random noise using DSP32c */
  22.  
  23. void ran32 (ioval)
  24. unsigned long *ioval;
  25. {
  26.  
  27. #define  C    0x234567
  28. #define  Alo  0x007465
  29. #define  Ahi  0x000010
  30.  
  31.   unsigned long Rlo, Rhi;
  32.   unsigned long ar1, ar2, ar3;
  33.   unsigned long t1, t2, t3;
  34.  
  35.   Rlo = *ioval & 0x00ffff;
  36.   Rhi = *ioval >> 16;
  37.   ar1 = Alo * Rlo;
  38.   ar2 = Alo * Rhi;
  39.   ar3 = Ahi * Rlo;
  40.   t1 = (ar2 + ar3);
  41.   t2 = t1 << 16;
  42.   t3 = ar1 + t2;
  43.   *ioval = C + t3;
  44. }
  45.  
  46.