vbdpss.hlp (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
Article Q28150
                                                 Contents  Index  Back
─────────────────────────────────────────────────────────────────────────────
                           Knowledge Base Contents  Knowledge Base Index
 
 Alternatives to RND and RANDOMIZE for Generating Random Numbers, Example 2
 
 Code Example 2
 --------------
 
 The following is the same as Example 1, except the random numbers are
 plotted to illustrate their uniform distribution:
 
 ' To try this example in VBDOS.EXE:
 ' 1. From the File menu, choose New Project.
 ' 2. Copy the code example to the Code window.
 ' 3. Press F5 to run the program.
 
 DEFDBL A-Z     ' Requires double-precision intermediate variables.
 SCREEN 2
 a = 214013
 c = 2531011
 z = 2 ^ 24
 INPUT "Input seed value: ", x0
 FOR count = 1 TO 5000
   temp = x0 * a + c
   ' Calculate (temp MOD z) and assign to x1:
   temp = temp / z
   x1 = (temp - FIX(temp)) * z
   result = x1 / z  ' Result is between 0.000000 and 1.000000
   GOSUB 100       ' Plot Result
   x0 = x1   ' x0 and x1 range from 0 to 16777216 (2^24)
 NEXT
 END
 ' Plot the random points to see their uniform distribution:
 100 y = y + 1
     IF y > 200 THEN y = 0   ' Wrap plot at y=200 pixels.
     x = result * 500   ' Assumes screen mode <= 500 pixels wide.
     PSET (x, y)   ' PSET requires a graphics screen mode.
     RETURN