Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class
RANDOM_WALK
feature
simulate (steps: INTEGER)
local i, position: INTEGER
do
position := 0
from i := 1 until i > steps loop
if random(2) = 0 then
position := position + 1
else
position := position - 1
end
io.put_integer(position); io.put_new_line
i := i + 1
end
end
end
! Run
local
rw: RANDOM_WALK
do
create rw
rw.simulate(10)
endCoding works best on desktop or with an external keyboard.