' {$STAMP BS2}
' {$PBASIC 2.5}

result  VAR     Word
final    VAR     Byte
row3  CON 0
row2  CON 1
row1  CON 2
LED1  CON 11
LED2  CON 10
LED3  CON 9
LED4  CON 8
LED5  CON 7
LED6  CON 6
LED7  CON 5
LED8  CON 4
LED9  CON 3


OUTPUT 0
OUTPUT 1
OUTPUT 2
OUTPUT 3
OUTPUT 4
OUTPUT 5
OUTPUT 6
OUTPUT 7
OUTPUT 8
OUTPUT 9
OUTPUT 10
OUTPUT 11

HIGH row1
HIGH row2
HIGH row3
LOW LED1
LOW LED2
LOW LED3
LOW LED4
LOW LED5
LOW LED6
LOW LED7
LOW LED8
LOW LED9

DO
counter VAR  Byte

 result = 1111            ' set initial "seed" value


Main:
PAUSE 500
FOR counter = 1 TO 10

final =((result//27) +1)
RANDOM result                    ' generate random number
PAUSE 500
DEBUG DEC ? final              ' show the result on screen


 IF (final = 1) THEN
   LOW row3
   HIGH led1
   PAUSE 500
   HIGH row1
   LOW led1
  ELSEIF (final = 2) THEN
   LOW row3
   HIGH led2
   PAUSE 500
   HIGH row1
   LOW led2
  ELSEIF (final = 3) THEN
   LOW row3
   HIGH led3
   PAUSE 500
   HIGH row1
   LOW led3
     ELSEIF (final = 4) THEN
   LOW row3
   HIGH led4
   PAUSE 500
   HIGH row1
   LOW led4
     ELSEIF (final = 5) THEN
   LOW row3
   HIGH led5
   PAUSE 500
   HIGH row1
   LOW led5
     ELSEIF (final = 6) THEN
   LOW row3
   HIGH led6
   PAUSE 500
   HIGH row1
   LOW led6
     ELSEIF (final = 7) THEN
   LOW row3
   HIGH led7
   PAUSE 500
   HIGH row1
   LOW led7
     ELSEIF (final = 8) THEN
   LOW row3
   HIGH led8
   PAUSE 500
   HIGH row1
   LOW led8
    ELSEIF (final = 9) THEN
   LOW row3
   HIGH led9
   PAUSE 500
   HIGH row1
   LOW led9

  ELSEIF (final = 10) THEN
   LOW row2
   HIGH led10
   PAUSE 500
   HIGH row2
   LOW led10
        ELSEIF (final = 11) THEN
   LOW row2
   HIGH led11
   PAUSE 500
   HIGH row2
   LOW led11
        ELSEIF (final = 12) THEN
   LOW row2
   HIGH led12
   PAUSE 500
   HIGH row2
   LOW led12
        ELSEIF (final = 13) THEN
   LOW row2
   HIGH led13
   PAUSE 500
   HIGH row2
   LOW led13
        ELSEIF (final = 14) THEN
   LOW row2
   HIGH led14
   PAUSE 500
   HIGH row2
   LOW led14
        ELSEIF (final = 15) THEN
   LOW row2
   HIGH led1
   PAUSE 500
   HIGH row2
   LOW led1
        ELSEIF (final = 16) THEN
   LOW row2
   HIGH led1
   PAUSE 500
   HIGH row2
   LOW led1
           ELSEIF (final > 16) THEN
    IF (final = 17) THEN
   LOW row2
   HIGH led1
   PAUSE 500
   HIGH row2
   LOW led1
        ELSEIF (final = 18) THEN
   LOW row3
   HIGH led2
   PAUSE 500
   HIGH row1
   LOW led1
        ELSEIF (final = 19) THEN
   LOW row3
   HIGH led1
   PAUSE 500
   HIGH row1
   LOW led1
        ELSEIF (final = 20) THEN
   LOW row3
   HIGH led1
   PAUSE 500
   HIGH row1
   LOW led1
        ELSEIF (final = 21) THEN
   LOW row3
   HIGH led1
   PAUSE 500
   HIGH row1
   LOW led1
        ELSEIF (final = 22) THEN
   LOW row3
   HIGH led1
   PAUSE 500
   HIGH row1
   LOW led1
        ELSEIF (final = 23) THEN
   LOW row3
   HIGH led1
   PAUSE 500
   HIGH row1
   LOW led1
        ELSEIF (final = 24) THEN
   LOW row3
   HIGH led1
   PAUSE 500
   HIGH row1
   LOW led1
        ELSEIF (final = 25) THEN
   LOW row3
   HIGH led1
   PAUSE 500
   HIGH row1
   LOW led1
   ENDIF
   ENDIF

PAUSE 500
NEXT
LOOP