Here is a program that computes an uncomputable real number (probably, but the probability is arbitrarily close to zero) .
That sounds paradoxical, but is really just ironic.
note
description: "Program that generates an uncomputable number on stdout in the range [0,1)"
author: "Colin Adams"
class UNCOMPUTABLE
create
make
feature {NONE} -- Initialization
random_generator: RANDOM
-- Source of decimal digits
seed: INTEGER
-- Seed for `random_generator'
make
-- Run application.
local
i: INTEGER
do
set_seed
create random_generator.set_seed (seed)
print ("%N0.")
from
set_seed
i := seed.abs
until
False
loop
random_generator.forth
print (random_generator.item \\ 10)
i := i - 1
if i = 0 then
set_seed
create random_generator.set_seed (seed)
set_seed
i := seed.abs
end
end
end
feature {NONE} -- Implementation
set_seed
-- Set value for `seed' by reading 4 bytes from /dev/random.
--| `make_open_read' fails the precondition of `readable'
--| because of /dev/random is always 0. Maybe this
--| precondition should be considered too strict.
--| Work-around is to compile without assertions enabled.
local
l_file: RAW_FILE
do
create l_file.make_open_read ("/dev/random")
l_file.read_integer
seed := l_file.last_integer
l_file.close
end
end