Generating random numbers

The CommonPoint system provides classes to generate random integers and floating-point numbers. You can use the floating-point generator to test a function such as SampleArcTanh, discussed on page 186. One good place to test SampleArcTanh is at , the seam between the two forms of approximation. Here is a straightforward test function:

      void RandomTest(int testCount) {
          TUniformRandomDouble randomDelta;   // initialize generator
          const double_t kBand = 0x1.0p-10;   // width of test band
          const double_t kSeam = 0x1.0p-27;
          const double_t kTolerance = 1.0E-15;
          for (int i = 0; i < testCount; i++) {
              double testArg = kSeam + (randomDelta.Next() - 0.5) * kBand;
              if (ExcessiveRelativeError(
                      SampleArcTanh(testArg),
                      SlowButSureArcTanh(testArg),
                      kTolerance))
                  ReportSuspiciousError(testArg);
          }
      }
The member function Next delivers successive random values uniformly distributed between 0 and 1. The result is a sequence of test values uniformly distributed in a band of width kBand, centered at kSeam.


[Contents] [Previous] [Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.

Generated with WebMaker