$MLC F 100 10 3000
300 INPUT "Pixels per run : ":N
310 CALL LINK("TEST",N)
320 END
$TEST
    GETPARAM 1 N                ; how many pixels said the user
    XREGENABLE                  ; access enabled to extended registers
    STARTDATA
        byte &hE0               ; BML def bloc, first byte is flags
        byte &h40               ; then address (here 64*64 = 4096)
        bytes 64,32,128,128     ; then x,y,w,h
    ENDDATA E
    BMLSET 0 E
    BMLPLOT 0 0 0
    BMLFILLRECT 128 128
    BMLSET 1 E                  ; and display the BML
    REPEAT
        NDO I N                 ; N times
            RND                 ; RND always return in Z
            AND Z 127           ; mask to get 0-127
            LET X Z             ; X = 0-127
            RND
            AND Z 127
            LET Y Z             ; same Y = 0-127
            RND
            AND Z 3             ; Z = 0-3, the color!
            BMLPLOT X Y Z       ; plot the pixel
        NLOOP
        RND
        AND Z 15                ; Z=0-15 a palette number
        ADD Z &hE0              ; + flags
        PUTTABLE E(0) Z         ; new flags
        BMLSET 1 E              ; set new parameters for BML
        KEY 0                   ; a key stroke?
    UNTIL>=                     ; if >= then non, repeat!
    PUTTABLE E(0) &h60          ; else, change flags to "BML disabled"
    BMLSET 1 E                  ; and set new parameters
$$
$END

    