so-un-bot/Ingegneria del Software/0721_38/correct.txt
2022-11-16 18:08:57 +01:00

27 lines
No EOL
512 B
Text

<pre>
block MarkovChain
//external function myrandom() returns a random real number in [0, 1]
parameter Integer x0 = 0;
parameter Integer xmax = 100;
OutputInteger x;
algorithm
when initial() then
x := x0;
elsewhen sample(0, 1) then
if (x < xmax)
then
if (myrandom() <= 0.9)
then
if (myrandom() <= 0.8)
then
x := x + 1;
else
x := max(0, x - 1);
end if;
else
x := max(0, x - 1);
end if;
end if;
end when;
end MarkovChain;
</pre>