import random


def random_fill_sparse(table,K):
    """
    brief : fills in a matrix randomly
    
    args : 
        matrix : empty matrix
        K : number of cells to be filled in
    
    Return :
        the matrix (numpy array) filled in with "X" values (char)
    
    Raises : 
        K must be smaller than the table size
        The table must contain Char type values 
    """

    i=0
    y=0#matrix lines
    x=0#matrix column
    
    if K>table.size:
         raise ValueError('K is out of bounds')
         
    if table.dtype != "<U1":
         raise ValueError('The array type must be Char')
      
    
    while i < K:
        y=random.randrange(0,len(table)-1)
        x=random.randrange(0,len(table[0])-1)
        if table[y][x] != "X":
            table[y][x] = "X"
            i=i+1
    return table