Contents:

1. Introduction

This program implements a "Pseudo-Random Number Generator". All generated numbers are 160 bits long; it also allows for having more than one "sequence" going on at the same time (eg. with different seeds).

2. Overview

We have only two functions, make-sequence which initializes a sequence object given a seed, and next-number that returns the next number in the sequence given a sequence object.

Overview

make-sequence: func [
 "Create a random number sequence"
 seed [binary!]
] [
 Initialize a sequence object
]
next-number: func [
 "Return the next number from the sequence"
 sequence [object!]
] [
 Generate the next number in the sequence
]

3. Implementation

The implementation is trivial and is based on keyed SHA-1 (HMAC).

3.1 Initialize a sequence object

Initialize a sequence object

context [
 cur: #{0000000000000000000000000000000000000000}
 key: seed
]

3.2 Generate the next number in the sequence

Generate the next number in the sequence

sequence/cur: checksum/secure/key sequence/cur sequence/key