Middle-square method

class MiddleSquareMethod(seed, k = 1000) {
    method next {
        seed = (seed**2 // k % k**2)
    }
}
 
var obj = MiddleSquareMethod(675248)
say 5.of { obj.next }

Output:

[959861, 333139, 981593, 524817, 432883]

Last updated