(n, k=None)
return randarr[0:k]
Generate a random array which contains k elements range from (n[0]:n[1])

    Parameters
    ----------
    n: int or tuple
        range from [n[0]:n[1]], include n[0] and n[1].
        if an int is given, then n[0] = 0

    k: int, optional (default=end - start + 1)
        how many numbers will be generated. should not larger than n[1]-n[0]+1,
        default=n[1] - n[0] + 1.

    Returns
    -------
    perm: list
        the generated array.
Generate a random array which contains k elements range from (n[0]:n[1])
Generate a random array which contains k elements range from ( n [ 0 ] : n [ 1 ] )
def randperm(n, k=None):
    """Generate a random array which contains k elements range from (n[0]:n[1])

    Parameters
    ----------
    n: int or tuple
        range from [n[0]:n[1]], include n[0] and n[1].
        if an int is given, then n[0] = 0

    k: int, optional (default=end - start + 1)
        how many numbers will be generated. should not larger than n[1]-n[0]+1,
        default=n[1] - n[0] + 1.

    Returns
    -------
    perm: list
        the generated array.
    """
    if isinstance(n, np.generic):
        # n = np.asscalar(n)  # deprecated in numpy v1.16
        n = n.item()
    if isinstance(n, tuple):
        if n[0] is not None:
            start = n[0]
        else:
            start = 0
        end = n[1]
    elif isinstance(n, int):
        start = 0
        end = n
    else:
        raise TypeError("n must be tuple or int.")

    if k is None:
        k = end - start + 1
    if not isinstance(k, int):
        raise TypeError("k must be an int.")
    if k > end - start + 1:
        raise ValueError("k should not larger than n[1]-n[0]+1")

    randarr = np.arange(start, end + 1)
    np.random.shuffle(randarr)
    return randarr[0:k]
def randperm ( n , k = None ) : if isinstance ( n , np . generic ) : # n = np.asscalar(n)  # deprecated in numpy v1.16 n = n . item ( ) if isinstance ( n , tuple ) : if n [ 0 ] is not None : start = n [ 0 ] else : start = 0 end = n [ 1 ] elif isinstance ( n , int ) : start = 0 end = n else : raise TypeError ( "n must be tuple or int." ) if k is None : k = end - start + 1 if not isinstance ( k , int ) : raise TypeError ( "k must be an int." ) if k > end - start + 1 : raise ValueError ( "k should not larger than n[1]-n[0]+1" ) randarr = np . arange ( start , end + 1 ) np . random . shuffle ( randarr ) return randarr [ 0 : k ]