```
:For(P,1,length(Str1)-1,1)
:inString(Str1,sub(Str2,P,1))-1→A
```

Your loop is iterating over Str1, but you're taking a substring of Str2. If Str1 is longer than Str2 then P can attain values greater than the length of Str, so you're trying to access an element of Str2 that doesn't exist.

Also, I'd like to point out a few things.

```
:Disp "KEY(NUM)?"
:Input X
```

Input can take two arguments: (1) the prompt string, and (2) the variable. The above lines (plus the two following them) can be condensed to one command/line.

If the increment of a For( loop is one, you can leave it out.

The round( command needs two arguments, so unless you specify the number of digits no rounding will occur.

EDIT by Rhombus: fixed your Code problems

[edit] @Rhombus: Thanks, I didn't notice that.

@Matthias1992: I think you overcomplicated a couple of lines.

```
:If E
:fPart((A+int(27rand))/27)*27→A
:If not(E)
:fPart((A+(27-int(27rand)))/27)*27→A
```

int(27rand) is functionally equivalent to randInt(0, 26) (see

here), so it will give you a random integer (let's say N) in the range 0≤N≤26 (possibly 27, but that's so unlikely you can pretty much ignore it). 27-int(27rand) will give you a random integer in the range 27≥N≥1, or 1≤N≤27 (possibly zero, but again it's reeeally unlikely). That code can now be simplified to

```
:If E
:27fPart((A+randInt(0,26))/27)→A
:If not(E)
:27fPart((A+1+randint(0,26))/27)→A
```

Since E can only take on the values 0 and 1 (unless the user screwed up) and the only difference between those two calculations is 1, it can be simplified to

`:27fPart((A+not(E)+randInt(0,26))/27)→A`

As I was typing this out I realized that int(27rand) is smaller than randInt(0,26), so the code finally becomes

`:27fPart((A+not(E)+int(27rand))/27→A`