esolang

Random

The program is its only memory, and every plain character it runs makes it one character longer.

Gs30ng, 2006 · Turing complete: unknown · ●●○ moderate · esolangs.org

Tested with 2 known programs · Test method

Run it

Expected: Hello, World!

The idea

Gs30ng proposed Random, the R and O Machine, in 2006. The source code is a double-ended stack and the program works on itself. A plain character appends a copy of itself to the back, so the one letter program A grows to AA, then AAA, and never stops. Five instructions move characters between the two ends, print the back one or loop.

Read the story

The specification says the spec is still being developed. Random can keep two stacks, one at each end, and the specification guesses that this makes it Turing complete.

The machine

InstructionDoes
any other characterAppend a copy of itself to the back
<Move the back character to the front
>Move the front character to the back
><Remove the back character and print it
[Jump past its ] if the front and back characters are the same
]Jump back past its [ if they differ

A pointer runs from the left, and the run ends when it passes the back.

Example

The first 13 characters append themselves, so the back holds !dlroW ,olleH a second time.

The first 13 characters append themselves, so the back holds !dlroW ,olleH a second time. The loop prints from the back, H first, while the back differs from the front !. When only the copied ! is left, the last >< prints it and the pointer passes the back.

The same loop prints any text without <, >, [ and ] that has a mark in front which the text does not use. The < at the end moves the copied mark to the front, and the pointer is past the back.

Expected: Hi!

The specification also traces A<<B. It becomes A<<BA, then AA<<B, then BAA<<, and prints nothing.

Patterns it teaches

Further

String-rewriting paradigm

Self-modifying

Write your own in Run Convert a program from Random

Implementation

JavaScript interpreter, source and command line

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

Command line

shib run random -e 'A<<B'
shib manual random

Source

Module
langs/wiki/ports.js
Interpreter
langs/wiki/random.js

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

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