Basic compiler MachiKania type P for PicoCalc

MachiKania is an integer BASIC compiler with availability of float and string. So, most of the functions are provided as integer ones. Therefore, the rnd() function is provided as integer value and cannot be the value between 0 and 1.

Following code prints float values between 0 and 1 several times.

for i=1 to 100
  print gosub#(frand),
next
end

label frand
  return float#(rnd())/32768

To generate randomized rnd() result, I recommend to call rnd() function for the number of times specified by human as follows:

do while inkey():loop
print "hit any key"
do until inkey()
  i=rnd()
loop
print rnd()

Alternatively, the system(101) returns the pointer to the random seed. It can be handled as follows:

poke32 system(101), xxxxxxxx

, where “xxxxxxxx” is randomized number by timer etc.

1 Like