# Subtractive generator

```ruby
class SubRandom(seed, state=[]) {
 
    const mod = 1_000_000_000
 
    method init {
        var s = [seed % mod, 1]
        53.times {
            s.append((s[-2] - s[-1]) % mod)
        }
        state = s.range.map {|i| s[(34 + 34*i) % 55] }
        165.times { self.subrand }
    }
 
    method subrand {
        var x = ((state.shift - state[-24]) % mod)
        state.append(x)
        return x
    }
}
 
var r = SubRandom(292929)
10.times { say r.subrand }
```

#### Output:

```
467478574
512932792
539453717
20349702
615542081
378707948
933204586
824858649
506003769
380969305
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/s/subtractive_generator.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
