12.1 Simulating rolling one die.

To simulate rolling a die, we’re going to use the primitive random. Here’s how it works:.



random 6 → returns a randomly choosen integer among 0, 1, 2, 3, 4, 5.

Hence, (random 6)+1 returns a randomly choosen integer from 1, 2, 3, 4, 5, 6. We need the parenthesis, otherwise, the LOGO interpreter should understand random 7. To avoid parenthesis, we can write 1+random 6 too.



We define the primitive called die which simulates rolling one die.

 to die
    output 1+random 6
  end