From 4b95b99d47b000c4311db98d1c50190ffaab1774 Mon Sep 17 00:00:00 2001 From: Richard Nienaber Date: Tue, 8 Sep 2026 11:14:14 +0100 Subject: [PATCH] seed and tape Perl and Lua ports Perl is the largest gap in the corpus after the JVM and .NET work: 75 ports, more than any language the shipped runners did not already cover. Lua is smaller but comes almost free, and both hook the same way -- an environment variable naming a file the interpreter runs before the program. Perl's shim arrives through PERL5OPT=-M, which loads it before the program is compiled. That ordering is not a preference: a call to `rand` consults *CORE::GLOBAL::rand when it is compiled, so an override installed any later is not seen. The same rule applies inside the module -- its own `my` declarations run after its BEGIN block, so the state the override closes over is held in package variables initialised in BEGIN. Lua's arrives through LUA_INIT=@file. math.random and math.randomseed are ordinary table fields, so the tape path replaces both outright. Both follow the house rule: a tape replaces the draw function and neutralises the seeding function, while seeded mode only seeds the language's own generator and leaves a port's own reseed alone. The seeded rows in the test are each language's own generator -- drand48 for Perl, xoshiro256** for Lua -- checked across two versions rather than taken from one machine, so the container and a developer's host agree. Lua is not in debian:bookworm-slim, so the image now installs lua5.4, whose package registers /usr/bin/lua through alternatives; perl is already there. CI installs lua5.4 to match. Co-Authored-By: Claude Opus 5 Claude-Session: https://claude.ai/code/session_019f9gkZVUEo3jtv51GSb4vJ --- .github/workflows/ci.yaml | 5 + README.md | 7 +- docker/Dockerfile | 17 +++- docs/container.md | 4 +- docs/determinism.md | 43 ++++++-- internal/play/runner_integration_test.go | 9 +- runners/lua.yaml | 27 +++++ runners/lua/random.lua | 104 +++++++++++++++++++ runners/perl.yaml | 25 +++++ runners/perl/prescript.pm | 122 +++++++++++++++++++++++ test/fixtures/rng/rng.lua | 13 +++ test/fixtures/rng/rng.pl | 12 +++ 12 files changed, 367 insertions(+), 21 deletions(-) create mode 100644 runners/lua.yaml create mode 100644 runners/lua/random.lua create mode 100644 runners/perl.yaml create mode 100644 runners/perl/prescript.pm create mode 100644 test/fixtures/rng/rng.lua create mode 100644 test/fixtures/rng/rng.pl diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 1273af2..333f98c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -44,6 +44,11 @@ jobs: with: dotnet-version: '10.0.x' + # Perl is already on the image; Lua is not, and 5.4 is what the + # container has. + - name: install lua + run: sudo apt-get install --no-install-recommends --yes lua5.4 + # The Java shim is a jar, so unlike every other runner's it has to exist # before the suite can use it. - name: make shims diff --git a/README.md b/README.md index 6417051..1ee0f42 100644 --- a/README.md +++ b/README.md @@ -201,9 +201,10 @@ testable: prescript play scripts/33-dice.yaml --runner runners/ruby.yaml -- 33_Dice/ruby/dice.rb ``` -Ruby, Python, Node, Java and .NET ship and take a tape; Go ships and can be -seeded but not taped. All are covered by tests. The Java shim is a javaagent -jar, so it has to be built once with `make shims` before its runner will work. +Ruby, Python, Node, Perl, Lua, Java and .NET ship and take a tape; Go ships and +can be seeded but not taped. All are covered by tests. The Java shim is a +javaagent jar, so it has to be built once with `make shims` before its runner +will work. A seed makes one port repeatable, but the same seed gives each language a different sequence, so one script still cannot serve them all. `--tape` closes diff --git a/docker/Dockerfile b/docker/Dockerfile index 82e8bcf..28868e9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -20,11 +20,14 @@ ARG BASE_DIGEST=sha256:88200866dfff7ea7f5cbcb6ec7c8a701889efe6fe859fe64d6990e4b0 FROM --platform=linux/amd64 debian:bookworm-slim@${BASE_DIGEST} ARG BASE_DIGEST -# Ruby and Python come from Debian stable, which is what pinning means for a -# distribution: a fixed series that takes security fixes and no new features -# for the life of the release. Go, Node, Java, .NET and the reference -# interpreter are not in it, so they are fetched from upstream and checked -# against a published checksum before anything is unpacked. +# Ruby, Python, Perl and Lua come from Debian stable, which is what pinning +# means for a distribution: a fixed series that takes security fixes and no new +# features for the life of the release. Lua's package registers /usr/bin/lua +# through alternatives, which is the name runners/lua.yaml starts. +# +# Go, Node, Java, .NET and the reference interpreter are not in it, so they are +# fetched from upstream and checked against a published checksum before +# anything is unpacked. ARG GO_VERSION=1.24.13 ARG GO_SHA256=1fc94b57134d51669c72173ad5d49fd62afb0f1db9bf3f798fd98ee423f8d730 ARG NODE_VERSION=24.20.0 @@ -50,7 +53,9 @@ RUN apt-get update \ ca-certificates \ curl \ git \ + lua5.4 \ make \ + perl \ python3 \ ruby \ tzdata \ @@ -140,6 +145,8 @@ RUN { \ echo "dotnet=$(dotnet --version)"; \ echo "python=$(python3 --version | cut -d' ' -f2)"; \ echo "ruby=$(ruby --version | cut -d' ' -f2)"; \ + echo "perl=$(perl -e 'print $^V')"; \ + echo "lua=$(lua -v | cut -d' ' -f2)"; \ echo "vintbas=${VINTBAS_RELEASE}"; \ echo "locale=${LC_ALL}"; \ echo "timezone=${TZ}"; \ diff --git a/docs/container.md b/docs/container.md index d60b112..53b761c 100644 --- a/docs/container.md +++ b/docs/container.md @@ -19,7 +19,7 @@ make docker_shell # look around | | How | | --- | --- | | Base | `debian:bookworm-slim` by digest | -| Ruby, Python | Debian stable, a fixed series taking security fixes only | +| Ruby, Python, Perl, Lua | Debian stable, a fixed series taking security fixes only | | Go, Node, Java | upstream tarballs, checked against a published SHA-256 | | .NET | the SDK tarball, checked against the SHA-512 Microsoft publishes | | vintbas | the same release asset the Makefile installs, checked the same way | @@ -77,6 +77,8 @@ java=25.0.4.1 dotnet=10.0.400 python=3.11.2 ruby=3.1.2p20 +perl=v5.36.0 +lua=5.4.4 vintbas=vintbas-1.0.3-1 locale=C.UTF-8 timezone=UTC diff --git a/docs/determinism.md b/docs/determinism.md index c6ff7a3..e63a552 100644 --- a/docs/determinism.md +++ b/docs/determinism.md @@ -58,6 +58,8 @@ prescript play scripts/33-dice.yaml --runner runners/ruby.yaml -- 33_Dice/ruby/d | Ruby | `RUBYOPT=-r` | `rand`, `Kernel#rand` | yes | | Python | `sitecustomize.py` on `PYTHONPATH` | the `random` module's functions | yes | | Node | `NODE_OPTIONS=--require ` | `Math.random` | yes | +| Perl | `PERL5OPT=-M` | `rand`, `srand` | yes | +| Lua | `LUA_INIT=@` | `math.random`, `math.randomseed` | yes | | Java | `-javaagent:` rewriting call sites | `Math.random`, `Random`, `ThreadLocalRandom` | yes | | .NET | a `System.Random` compiled in ahead of the real one | everything on `Random`, including `Shared` | yes | | Go | `GODEBUG=randautoseed=0` | `math/rand`'s global functions | no | @@ -104,6 +106,11 @@ program constructs for itself, or one that seeds itself deliberately: - Ruby: `Random.new(...)`, `SecureRandom` - Python: `random.Random(...)` instances, `secrets`, `numpy` - Node: `crypto.randomBytes`, `crypto.getRandomValues` +- Perl: `Math::Random::MT` and the other CPAN generators, `/dev/urandom` read + directly, and anything drawing inside an XS module rather than through Perl's + own `rand` +- Lua: a generator a port builds from `math.randomseed`'s return values, and + RNGs from LuaRocks - Java: `SecureRandom`, `SplittableRandom`, generators built by `RandomGeneratorFactory`, and draws made from inside `java.base` rather than from the port — `Collections.shuffle(list, rnd)` and `rnd.ints()` call @@ -128,15 +135,25 @@ platform. | Language | Mechanism | Why it is not here | | --- | --- | --- | +| Kotlin | the Java agent, plus `kotlin.random` in its owner list | JVM already; not yet verified against a port | +| VB.NET | a Visual Basic twin of the C# shim | `Rnd` and `Randomize` live in a module rather than a class | +| MiniScript | a patched interpreter seeded from the environment | `rnd` is an intrinsic and the interpreter has no launch hook | | Rust | `[patch.crates-io] getrandom` in `.cargo/config.toml` | build-time, not launch-time | | Haskell | vendored `random` with `initStdGen = pure (mkStdGen n)` | build-time, not launch-time | | C / C++ | `-include shim.h`, or a `rand.o` linked ahead of libc | build-time, not launch-time | -These are all the same problem: a compiled language's randomness is decided when -it is built, and a runner only gets to speak at launch. Java and .NET are in the -table above rather than in this one because both compile on the way to running, -which gives a runner a compilation to join; a Rust port arrives as a binary, or -as a build a runner would have to drive. +The bottom three are all the same problem: a compiled language's randomness is +decided when it is built, and a runner only gets to speak at launch. Java and +.NET are in the table above rather than in this one because both compile on the +way to running, which gives a runner a compilation to join; a Rust port arrives +as a binary, or as a build a runner would have to drive. + +The top three are near misses of different kinds. Kotlin is JVM bytecode, so the +Java agent already rewrites the ports that reach for `java.util.Random`, and +`kotlin.random` is a line in the agent's owner list away. MiniScript is the +largest single set of ports in the corpus and the only one with no launch hook +at all — the move that fits is the one already made for the reference +interpreter, which is patched and built from `patches/` rather than hooked. An untested runner is worse than a missing one — it makes a corpus look seeded when it is not — so these are listed rather than guessed at. @@ -162,14 +179,19 @@ underneath. The test fixtures show it plainly — one program, one seed: | Ruby | `548 715 602` | | Python | `844 757 420` | | Node | `358 105 675` | +| Perl | `170 749 96` | +| Lua | `246 234 69` | | Java | `730 240 637` | | .NET | `358 105 675` | | Go | `604 940 664` | -.NET agrees with Node because both shims substitute the same generator, for the -reason given above. Java's row is the JDK's own LCG, seeded the ordinary way. -That one agreement is a fact about two shims rather than a property anything -should lean on — a tape is how ports are made to agree on purpose. +Each row is the language's own generator, not a snapshot of one machine: Java's +is the LCG `java.util.Random` specifies exactly, Perl's is drand48, and Lua's is +the xoshiro256** it has used since 5.4 — checked against 5.4 and 5.5, which +agree. .NET agrees with Node because both shims substitute the same generator, +for the reason given above; that one agreement is a fact about two shims rather +than a property anything should lean on. A tape is how ports are made to agree +on purpose. So a seed makes each port repeatable, and one expected-output file still cannot serve them all. That is what a tape is for. @@ -189,8 +211,7 @@ prescript play scripts/33-dice.yaml --runner runners/ruby.yaml \ loaded switches from seeding to replaying. Nothing else about the run changes, and the port is still untouched. -The same tape through the Ruby, Python, Node, Java and .NET runners gives the -same transcript — which is the whole point, and is what +The same tape through every runner but Go's gives the same transcript — which is the whole point, and is what `TestOneTapeGivesEveryLanguageTheSameNumbers` checks. ### Where the numbers come from diff --git a/internal/play/runner_integration_test.go b/internal/play/runner_integration_test.go index 47d502c..24ab383 100644 --- a/internal/play/runner_integration_test.go +++ b/internal/play/runner_integration_test.go @@ -23,7 +23,10 @@ import ( // one machine's: Ruby and Python both promise a reproducible Mersenne Twister, // Go's is the fixed source it used before it started seeding itself, Java's is // the linear congruential generator java.util.Random specifies exactly, and -// Node's is the generator in runners/node/random.js. +// Node's is the generator in runners/node/random.js. Perl's is drand48, and +// Lua's the xoshiro256** it has used since 5.4 -- checked against both 5.4 and +// 5.5, which agree, so the row belongs to the language rather than to whichever +// one is installed. // // .NET draws what Node draws, and that is not a mistake. Its shim replaces // System.Random outright, so it has to bring a generator rather than seed one, @@ -41,6 +44,8 @@ var seededRunners = []struct { {runner: "go.yaml", program: "rng.go", drawn: "604 940 664"}, {runner: "java.yaml", program: "rng.java", drawn: "730 240 637"}, {runner: "dotnet.yaml", program: "rng.cs", drawn: "358 105 675"}, + {runner: "perl.yaml", program: "rng.pl", drawn: "170 749 96"}, + {runner: "lua.yaml", program: "rng.lua", drawn: "246 234 69"}, } func repositoryPath(t *testing.T, parts ...string) string { @@ -222,6 +227,8 @@ var tapedRunners = []struct { {runner: "node.yaml", program: "rng.js"}, {runner: "java.yaml", program: "rng.java"}, {runner: "dotnet.yaml", program: "rng.cs"}, + {runner: "perl.yaml", program: "rng.pl"}, + {runner: "lua.yaml", program: "rng.lua"}, } // referenceDraws is what the reference BASIC interpreter itself prints for diff --git a/runners/lua.yaml b/runners/lua.yaml new file mode 100644 index 0000000..518fa81 --- /dev/null +++ b/runners/lua.yaml @@ -0,0 +1,27 @@ +# How to start a Lua port, and how to make its randomness repeatable. +# +# prescript play dice.yaml --runner runners/lua.yaml +version: "0.8" +executable: lua + +env: + # The standalone interpreter runs this before the program, so a port does not + # have to be edited to be made deterministic. The leading @ is what makes it a + # file to run rather than a chunk to compile. ${runnerDir} is where this file + # lives, so the runner and its shim travel together whatever directory + # prescript is run from. + # + # Lua looks for LUA_INIT_5_4 (or _5_5, and so on) before falling back to this + # name, so a port run under a version-specific variable set by something else + # would not see the shim -- but nothing sets those by default. + LUA_INIT: "@${runnerDir}/lua/random.lua" + + # One variable seeds every language. Two ports of the same program still draw + # different numbers from it -- that is what a tape fixes, not a seed -- but + # each of them draws the same numbers every time. + PRESCRIPT_SEED: "0" + +# A lua installed by a version manager, and any C module a port loads, are both +# found through the environment. Pinning the environment is a container's job +# rather than a runner's. +inheritEnv: true diff --git a/runners/lua/random.lua b/runners/lua/random.lua new file mode 100644 index 0000000..6374706 --- /dev/null +++ b/runners/lua/random.lua @@ -0,0 +1,104 @@ +-- Makes a Lua port's randomness repeatable, in one of two ways. +-- +-- With PRESCRIPT_TAPE set, math.random returns values recorded from the +-- reference BASIC interpreter, in order, so this port and every other port of +-- the same program draw the same numbers. Without it, Lua's own generator is +-- seeded from PRESCRIPT_SEED, which makes this port repeatable but leaves it +-- drawing a different sequence from every other language. See +-- docs/determinism.md. +-- +-- Activated by LUA_INIT=@, which the standalone interpreter runs +-- before the program, so the program does not have to know it exists and does +-- not have to be edited. Lua looks for a version-specific LUA_INIT_5_4 first +-- and falls back to LUA_INIT, so the plain name works whichever 5.x is +-- installed. +-- +-- What this does not reach: a generator a port builds for itself with +-- math.randomseed's return values or an RNG from LuaRocks, and os.time or +-- os.clock used as a value rather than as a seed. + +local tape = os.getenv("PRESCRIPT_TAPE") + +if not tape or tape == "" then + local seed = tonumber(os.getenv("PRESCRIPT_SEED") or 0) or 0 + math.randomseed(math.tointeger(seed) or 0) + return +end + +local values = {} +for line in io.lines(tape) do + -- A fresh local rather than the loop variable, which 5.5 makes const. + local trimmed = line:match("^%s*(.-)%s*$") + if trimmed ~= "" and trimmed:sub(1, 1) ~= "#" then + values[#values + 1] = tonumber(trimmed) + end +end + +local drawn = 0 + +-- How much of the tape a port used is the number that separates a real logic +-- bug from a port that restructured its draws, so it is written down rather +-- than left to be inferred from the transcript. +-- +-- The count is rewritten after every draw rather than written once at exit, +-- because the number that matters is how much had been drawn when the run +-- stopped agreeing with the transcript -- and a run that diverged by hanging +-- is killed, which runs no exit handler at all. Rewriting in place is safe +-- without truncating: the count only ever grows, so its decimal form only ever +-- gets longer, and each write covers the last. +local usage_path = os.getenv("PRESCRIPT_TAPE_USAGE") +local usage = nil +if usage_path and usage_path ~= "" then + usage = io.open(usage_path, "w") + if usage then + usage:setvbuf("no") + end +end + +local function write_usage() + if not usage then + return + end + usage:seek("set", 0) + usage:write(drawn, "\n") +end + +-- Written from the start, so that a port which drew nothing at all says so +-- rather than saying nothing. +write_usage() + +-- Running off the end is an error rather than a wrap. A port that draws more +-- than the reference did has restructured how it consumes randomness, which is +-- a finding; silently starting the tape again would turn that finding into a +-- transcript that merely looks wrong somewhere further on. +local function next_value() + if drawn >= #values then + io.stderr:write(("prescript: the tape ran out after %d values; this port " .. + "draws more randomness than the reference did\n"):format(#values)) + os.exit(1) + end + + drawn = drawn + 1 + local value = values[drawn] + write_usage() + return value +end + +-- math.random's three shapes, in terms of one uniform value: no argument for a +-- float in [0,1), one for an integer in [1,m], two for an integer in [m,n]. +math.random = function(m, n) + local value = next_value() + + if m == nil then + return value + end + + if n == nil then + m, n = 1, m + end + + return m + math.floor(value * (n - m + 1)) +end + +-- A port that seeds itself is asking for a sequence it has already been given. +math.randomseed = function() end diff --git a/runners/perl.yaml b/runners/perl.yaml new file mode 100644 index 0000000..0f0d90b --- /dev/null +++ b/runners/perl.yaml @@ -0,0 +1,25 @@ +# How to start a Perl port, and how to make its randomness repeatable. +# +# prescript play dice.yaml --runner runners/perl.yaml +version: "0.8" +executable: perl + +env: + # Perl loads this before it compiles the program, so a port does not have to + # be edited to be made deterministic -- and the ordering is not incidental: + # an override of rand has to be in place before the program's call sites are + # compiled, or they bind to the built-in. -I puts the shim's directory on the + # module path so -M can name it. ${runnerDir} is where this file lives, so + # the runner and its shim travel together whatever directory prescript is run + # from. + PERL5OPT: "-I${runnerDir}/perl -Mprescript" + + # One variable seeds every language. Two ports of the same program still draw + # different numbers from it -- that is what a tape fixes, not a seed -- but + # each of them draws the same numbers every time. + PRESCRIPT_SEED: "0" + +# A perl installed by perlbrew or plenv finds its own modules through the +# environment, and a port with dependencies resolves them through it too. +# Pinning the environment is a container's job rather than a runner's. +inheritEnv: true diff --git a/runners/perl/prescript.pm b/runners/perl/prescript.pm new file mode 100644 index 0000000..7a3b9d3 --- /dev/null +++ b/runners/perl/prescript.pm @@ -0,0 +1,122 @@ +# Makes a Perl port's randomness repeatable, in one of two ways. +# +# With PRESCRIPT_TAPE set, rand returns values recorded from the reference +# BASIC interpreter, in order, so this port and every other port of the same +# program draw the same numbers. Without it, Perl's own generator is seeded +# from PRESCRIPT_SEED, which makes this port repeatable but leaves it drawing a +# different sequence from every other language. See docs/determinism.md. +# +# Activated by PERL5OPT=-M, which Perl loads before it compiles +# the program, so the program does not have to know it exists and does not have +# to be edited. That ordering is what makes the override work at all: +# CORE::GLOBAL::rand is consulted when a call to rand is compiled, so an +# override installed afterwards would arrive too late for every call site in +# the program. +# +# What this does not reach: Math::Random::MT and the other generators from +# CPAN, /dev/urandom read directly, and anything whose randomness comes from a +# compiled XS module rather than from Perl's own rand. + +package prescript; + +use strict; +use warnings; + +# Core, and needed for autoflush below: the draw count has to reach the disk +# before the run it describes is killed. +use IO::Handle; + +# Package variables rather than lexicals, and set inside the BEGIN block below +# rather than here. The whole shim runs at compile time, and a module's own +# runtime statements -- these declarations included -- do not run until after +# it has been compiled, so a `my $drawn = 0` here would execute after the +# override that depends on it and reset what BEGIN had set up. +our @values; +our $drawn; +our $usage; + +# Running off the end is an error rather than a wrap. A port that draws more +# than the reference did has restructured how it consumes randomness, which is +# a finding; silently starting the tape again would turn that finding into a +# transcript that merely looks wrong somewhere further on. +sub next_value { + if ( $drawn >= @values ) { + die "prescript: the tape ran out after " + . scalar(@values) + . " values; this port draws more randomness than the reference did\n"; + } + + my $value = $values[ $drawn++ ]; + write_usage(); + return $value; +} + +# The count is rewritten after every draw rather than written once at exit, +# because the number that matters is how much had been drawn when the run +# stopped agreeing with the transcript -- and a run that diverged by hanging is +# killed, which runs no END block at all. +# +# Rewriting in place is safe without truncating: the count only ever grows, so +# its decimal form only ever gets longer, and each write covers the last. +sub write_usage { + return unless $usage; + + seek $usage, 0, 0; + print {$usage} "$drawn\n"; +} + +sub load_tape { + my ($path) = @_; + + open my $tape, '<', $path + or die "prescript: cannot read the tape at $path: $!\n"; + while ( my $line = <$tape> ) { + $line =~ s/^\s+|\s+$//g; + next if $line eq '' || $line =~ /^#/; + push @values, $line + 0; + } + close $tape; +} + +BEGIN { + @values = (); + $drawn = 0; + + my $tape = $ENV{PRESCRIPT_TAPE}; + + if ( defined $tape && $tape ne '' ) { + load_tape($tape); + + # How much of the tape a port used is the number that separates a real + # logic bug from a port that restructured its draws, so it is written + # down rather than left to be inferred from the transcript. Written from + # the start, so that a port which drew nothing at all says so rather + # than saying nothing. + my $path = $ENV{PRESCRIPT_TAPE_USAGE}; + if ( defined $path && $path ne '' ) { + open $usage, '>', $path + or die "prescript: cannot write the draw count to $path: $!\n"; + $usage->autoflush(1); + write_usage(); + } + + # rand's two shapes, in terms of one uniform value: no argument (or 0, + # which Perl treats as 1) for a float in [0,1), and an expression for + # [0,n). srand becomes a no-op rather than an error, because a port that + # seeds itself is asking for a sequence it has already been given. + no warnings 'once'; + *CORE::GLOBAL::rand = sub (;$) { + my $limit = @_ ? $_[0] : 1; + $limit = 1 unless $limit; + return next_value() * $limit; + }; + *CORE::GLOBAL::srand = sub (;$) { return 0 }; + } + else { + my $seed = $ENV{PRESCRIPT_SEED}; + $seed = 0 unless defined $seed && $seed =~ /^-?[0-9]+$/; + srand($seed); + } +} + +1; diff --git a/test/fixtures/rng/rng.lua b/test/fixtures/rng/rng.lua new file mode 100644 index 0000000..be7d9a9 --- /dev/null +++ b/test/fixtures/rng/rng.lua @@ -0,0 +1,13 @@ +-- A port in miniature: it asks something, then prints numbers it drew at +-- random. Without a seed those numbers differ on every run, which is what +-- makes a program like this impossible to script. +io.write("HOW MANY? ") +io.output():setvbuf("no") +local count = tonumber(io.read("l")) +-- INT(RND(1) * 1000), the way a port translates it. Written the same way in +-- every language here, so a tape gives all of them the same numbers. +local drawn = {} +for _ = 1, count do + drawn[#drawn + 1] = math.floor(math.random() * 1000) +end +print(table.concat(drawn, " ")) diff --git a/test/fixtures/rng/rng.pl b/test/fixtures/rng/rng.pl new file mode 100644 index 0000000..df5d25c --- /dev/null +++ b/test/fixtures/rng/rng.pl @@ -0,0 +1,12 @@ +# A port in miniature: it asks something, then prints numbers it drew at +# random. Without a seed those numbers differ on every run, which is what makes +# a program like this impossible to script. +use strict; +use warnings; + +$| = 1; +print "HOW MANY? "; +my $count = int( ); +# INT(RND(1) * 1000), the way a port translates it. Written the same way in +# every language here, so a tape gives all of them the same numbers. +print join( " ", map { int( rand() * 1000 ) } 1 .. $count ), "\n";