import random


def random_spmatrix(n_row, n_col, per_nnz):
    """
    This function output a random sparse matrix.

    Parameters
    ----------
    n_row : int
        Number of rows
    n_col : int
        Number of columns
    per_nnz : int
        Percentage of none zero elements

    Returns
    -------
    sp_matrix : list
        Sparse matrix without any storage format
    nnz_count : int
        Total none zero elements number
    row_max_nnz : int
        Row wise max none zero elements number

    Examples
    --------
    >>> n_row = 5
    >>> n_col = 5
    >>> per_nnz = 10
    >>> random_spmatrix(n_row, n_col, per_nnz)
    >>> # return a list fill with random data and 10% zero
    """

    if n_row < 0 or n_col < 0:
        raise ValueError('The number of rows or columns must > 0')

    if per_nnz < 0 or per_nnz > 100:
        raise ValueError('The percentage of nonzeros must between 0 - 100')

    sp_matrix = []
    nnz_count = 0
    row_max_nnz = 0

    for i in range(n_row):
        row_data = []
        row_nnz_count = 0
        for j in range(n_col):
            r_val = random.randint(0, 100)
            if r_val < per_nnz:
                row_data.append(0)
            else:
                nnz_count += 1
                row_nnz_count += 1
                row_data.append(r_val)
        row_max_nnz = max(row_max_nnz, row_nnz_count)
        sp_matrix.append(row_data)

    return sp_matrix, nnz_count, row_max_nnz