Middle-square_method Generator 
 The Method

To generate a sequence of n-digit pseudorandom numbers, an n-digit starting value is created and squared, producing a 2n-digit number. If the result has fewer than 2n digits, leading zeroes are added to compensate. The middle n digits of the result would be the next number in the sequence and returned as the result. This process is then repeated to generate more numbers.

 Pseudo code

var seed = 675248
function random()
    var s = str(seed * seed) 'str: turn a number into string
    do while not len(s) = 12
        s = "0" + s          'add zeroes before the string
    end do
    seed = val(mid(s, 4, 6)) 'mid: string variable, start, length
                             'val: turn a string into number
    return seed
end function

 Middle-square method use

for i = 1 to 5
    print random()
end for

Task

 Generate a class/set of functions that generates pseudo-random
numbers (6 digits) as shown above.

 Show the first five integers generated with the seed 675248 as shown above.
 Show your output here, on this page.
       IDENTIFICATION DIVISION.
       PROGRAM-ID. MIDDLE-SQUARE.
 
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 STATE.
          03 SEED         PIC 9(6) VALUE 675248.
          03 SQUARE       PIC 9(12).
          03 FILLER       REDEFINES SQUARE.
             05 FILLER    PIC 9(3).
             05 NEXT-SEED PIC 9(6).
             05 FILLER    PIC 9(3).
 
       PROCEDURE DIVISION.
       BEGIN.
           PERFORM SHOW-NUM 5 TIMES.
           STOP RUN.
 
       SHOW-NUM.
           PERFORM MAKE-RANDOM.
           DISPLAY SEED.
 
       MAKE-RANDOM.
           MULTIPLY SEED BY SEED GIVING SQUARE.
           MOVE NEXT-SEED TO SEED.