def int_to_charset(val, charset):
    """ Turn a non-negative integer into a string.

    >>> int_to_charset(0, B40_CHARS)
    '0'
    >>> int_to_charset(658093, B40_CHARS)
    'abcd'
    >>> int_to_charset(40, B40_CHARS)
    '10'
    >>> int_to_charset(149190078205533, B40_CHARS)
    'muneeb.id'
    >>> int_to_charset(-1, B40_CHARS)
    Traceback (most recent call last):
        ...
    ValueError: "val" must be a non-negative integer.
    """
    if val < 0:
        raise ValueError('"val" must be a non-negative integer.')
    if val == 0:
        return charset[0]
    output = ''
    while val > 0:
        val, digit = divmod(val, len(charset))
        output += charset[digit]
    return output[::-1]
