> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/p/pseudo-random-numbers/middle-square_method.md).

# Middle-square method

```ruby
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]
```
