    
    ' A proof of concept test of randomness vs compression ratio, proceed to example2.bas for a 
    ' practical compression/decompression example.
    
    
    '#define LZMA_DLL
    
    #include "inc/Lzma.bi"
    #libpath "lib/win32"
    
    const SAMPLE_DATA_SIZE = 5 * 1024 * 1024 ' 5 MB of random data
    const SAMPLE_INTERLEAVE = 8 * 1024
    const SAMPLE_ODDBITS = 0.30
    
    redim src(1 to SAMPLE_DATA_SIZE) as ubyte

    dim c as byte
    
    randomize timer
    
    print "Generating random sequences.. ";
    
    for i as integer = lbound(src) to ubound(src)
        if i mod (SAMPLE_INTERLEAVE) = 0 then
            c = rnd * 255
            print using "###%"; (i / ubound(src)) * 100;
            locate , pos - 4, 0
        end if
        src(i) = c
    next
    
    print "DONE"
    
    print using "Adding &% randomness overlay.. "; str(SAMPLE_ODDBITS * 100);
    
    for i as integer = lbound(src) to ubound(src) 
        if rnd < SAMPLE_ODDBITS then src(i) = rnd * 255
        if i mod (SAMPLE_INTERLEAVE) = 0 then
            print using "###%"; (i / ubound(src)) * 100;
            locate , pos - 4, 0
        end if        
    next
    
    print "DONE"
    
    redim dst(1 to SAMPLE_DATA_SIZE) as ubyte
    dim dstLen as uinteger = SAMPLE_DATA_SIZE
    dim outProps(1 to 5) as ubyte
    dim opLen as uinteger = 5
    
    
    print using "Compressing ##.## MB of sample data... "; SAMPLE_DATA_SIZE / (1024 * 1024);
    
    var r = LzmaCompress(@dst(1), dstLen, @src(1), SAMPLE_DATA_SIZE, @outProps(1), opLen)
    
    if r = SZ_OK then 
    
        redim preserve dst(1 to dstLen)
        
        print "DONE"
    
        print using "Compressed size: ##.## MB, Ratio: ##.#%"; dstLen / (1024 * 1024); (dstLen / SAMPLE_DATA_SIZE) * 100
    
    else
        print "ERROR "; r
        end 1
    end if
    
    sleep
    
    
    
    
    
    
    