import curses
import random
import time





ROW_DELAY=.0001

def get_rand_in_range(min, max):
    return random.randrange(min,max+1)

try:
    
    chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']

    total_chars = len(chars)

    stdscr = curses.initscr()
    curses.noecho()
    curses.curs_set(False)

    curses.start_color()
    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    stdscr.attron(curses.color_pair(1))

    max_x = curses.COLS - 1
    max_y = curses.LINES - 1


    

    

    columns_row = []

    
    

    columns_active = []

    for i in range(max_x+1):
        columns_row.append(-1)
        columns_active.append(0)

    while(True):
        for i in range(max_x):
            if columns_row[i] == -1:
                
                
                columns_row[i] = get_rand_in_range(0, max_y)
                columns_active[i] = get_rand_in_range(0, 1)

        

        for i in range(max_x):
            if columns_active[i] == 1:
                
                char_index = get_rand_in_range(0, total_chars-1)
                
                stdscr.addstr(columns_row[i], i, chars[char_index])
            else:
                
                
                stdscr.addstr(columns_row[i], i, );


            columns_row[i]+=1

            
            if columns_row[i] >= max_y:
                columns_row[i] = -1

            
            if get_rand_in_range(0, 1000) == 0:
                if columns_active[i] == 0:      
                    columns_active[i] = 1
                else:
                    columns_active[i] = 0

            time.sleep(ROW_DELAY)
            stdscr.refresh()

except KeyboardInterrupt as err:
    curses.endwin()