esolang

Seed

A program is two numbers: a length and a random seed. The seed is fed to a Mersenne Twister, and the random characters it spits out are run as Befunge.

2009 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 3 known programs · Hello World on Try It Online: identical · Test method

Run it

Expected: |"h",|

The idea

Seed appeared on esolangs.org in June 2009, added by the user Xp (the article names no author). A Seed program is length seed, for example 4 80814037. To run it:

Read the story
  1. Seed Python's random number generator (a Mersenne Twister) with the seed.
  2. Draw length characters, each one of 96: printable ASCII plus newline.
  3. Run the resulting text as a Befunge-98 program.

So writing a program is the easy part, and finding it is the hard part. You want a Befunge program; you must search for a seed that happens to produce it. The specification notes that brute force stops being practical at about six characters, because there are 96^n texts of length n.

Longer programs were found anyway, by people who work backwards through the Mersenne Twister. A 20-character Hello World needs a seed of more than 4,000 digits.

The machine

StepExactly
Parselength and seed, two integers separated by a space
Seedrandom.seed(seed) in Python 3: the integer is split into 32-bit words and fed to MT19937
Generatechars[int(random.random() * 96)], length times, where chars is ASCII 32–126 then \n
RunThe text, as Befunge-98

Every implementation must reproduce Python's generator bit for bit, or programs change meaning. This implementation does this in plain Node; it reimplements MT19937 and CPython's integer seeding.

Example

The specification lists these (found with its brute-force script):

The specification lists these (found with its brute-force script):

Seed programBefunge it makesDoes
1 186@Exit
2 20093~,Infinite cat (read a char, print it, wrap around)
4 80814037"h",Push h, print it: the "Hello, world" that only says h
4 141745954&&+.Read two numbers, add, print
Expected: the 780-character sample from the esolangs page

These two only show the text a seed makes. Without --mode program shib runs that text as Befunge-98, as TIO does. A three-character search found 3 147006, which makes a.@: push 10, print it, stop.

Expected: 10

All four rows, the 780-character sample, and both 20-character Hello Worlds in the specification were generated with this implementation; two of them were also checked against Python's own random. For "h",: the quotes push the character h, , prints it, and Befunge's wrap-around brings the pointer back to the start, so it keeps printing hhh…. The Hello World uses the Befunge-98 instruction k (repeat). It is the Hello World test TIO uses for Seed.

A surprise from running them: the two different 20-character Hello Worlds in the specification, by feersum and by Palaiologos, have different seeds (4,200 and 4,151 digits) but generate the same Befunge text: "9!dlroW ,olleH"ck,@. Many seeds, one program.

Patterns it teaches

  • Encoding tricks: the most extreme indirection on this wiki. The program is not written in any alphabet; it is an index into a random sequence.
  • Every text runs, sort of: every length seed pair yields some Befunge text, and Befunge runs most texts (unknown instructions reflect or do nothing, depending on the interpreter). The catch is that almost all of them do nothing interesting.
  • Two-dimensional control flow: the generated text is laid out as a 2D Befunge grid, newlines included.
  • Turing completeness: Seed can generate interpreters for universal languages (an SKI evaluator of length 112 is in the specification). Whether that makes Seed itself universal is argued, not settled.

Try this

  1. Run shib run seed -e '3 599084' --mode program. What Befunge does it make, and what does that program do?
  2. Write a brute-force search in Node (use run() from langs/museum/seed.js) for a 2-character program, such as .@. How many seeds did you try?
  3. Hard: write a program that prints hi and find a seed that makes it.

Further

  • esolangs.org/wiki/Seed, with the generator and brute-force scripts.
  • Befunge-98, the language Seed generates, and Befunge-93 before it.
  • Matsumoto and Nishimura, "Mersenne Twister" (1998), the generator Seed depends on.

Zero-dimensional languages

Write your own in Run Convert a program from Seed

Implementation

JavaScript interpreter, source and command line

A JavaScript interpreter, used in the browser and on the command line. Id: seed.

Command line

shib run seed -e '3 147006'
shib manual seed

Source

Module
langs/museum/ports.js
Interpreter
langs/museum/seed.js, langs/common.js, langs/tio/befunge-98.js, langs/museum/push.js

Docs: Kernel instructions · The .shib format · Command line · Adding a language

Source esolangs.org (CC0) · Edit on esolangs.org