* Linear Congruential Generator for deterministic pseudo-random numbers. * Constants from the classic C rand() implementation.
(n: number, seed = 0)
| 6 | * Constants from the classic C rand() implementation. |
| 7 | */ |
| 8 | function generateNumbers(n: number, seed = 0): number[] { |
| 9 | const results: number[] = []; |
| 10 | let current = seed; |
| 11 | |
| 12 | const a = 1664525; |
| 13 | const c = 1013904223; |
| 14 | const m = 2 ** 32; |
| 15 | |
| 16 | for (let i = 0; i < n; i++) { |
| 17 | current = (a * current + c) % m; |
| 18 | results.push(current); |
| 19 | } |
| 20 | |
| 21 | return results; |
| 22 | } |
| 23 | |
| 24 | /** Establish a baseline for computation performance in JS. |
| 25 | * Compute Engine calculations will be measured against this. |