*Generate a NumPy array of random distances given a sample number and distance limit*

    **Key Arguments:**
        - ``log`` -- logger
        - ``sampleNumber`` -- the sample number, i.e. array size
        - ``lowerRedshiftLimit`` -- the lower redshift limit of the volume to be included
        - ``upperRedshiftLimit`` -- the upper redshift limit of the volume to be included
        - ``redshiftResolution`` -- the resolution of the redshift distribution
        - ``pathToOutputPlotDirectory`` -- path to the output directory (provided by the user)
        - ``plot`` -- generate plot?

    **Return:**
        - ``redshiftArray`` -- an array of random redshifts within the volume limit

def random_redshift_array(
        log,
        sampleNumber,
        lowerRedshiftLimit,
        upperRedshiftLimit,
        redshiftResolution,
        pathToOutputPlotDirectory,
        plot=False):
    """
    *Generate a NumPy array of random distances given a sample number and distance limit*

    **Key Arguments:**
        - ``log`` -- logger
        - ``sampleNumber`` -- the sample number, i.e. array size
        - ``lowerRedshiftLimit`` -- the lower redshift limit of the volume to be included
        - ``upperRedshiftLimit`` -- the upper redshift limit of the volume to be included
        - ``redshiftResolution`` -- the resolution of the redshift distribution
        - ``pathToOutputPlotDirectory`` -- path to the output directory (provided by the user)
        - ``plot`` -- generate plot?

    **Return:**
        - ``redshiftArray`` -- an array of random redshifts within the volume limit
    """
    ################ > IMPORTS ################
    ## STANDARD LIB ##
    ## THIRD PARTY ##
    import matplotlib.pyplot as plt
    import numpy as np
    import numpy.random as npr
    ## LOCAL APPLICATION ##
    import dryxPython.astrotools as da

    redshiftDistribution = np.arange(
        0., upperRedshiftLimit, redshiftResolution)
    closestNumber = lambda n, l: min(l, key=lambda x: abs(x - n))

    # GIVEN THE REDSHIFT LIMIT - DETERMINE THE VOLUME LIMIT
    distanceDictionary = da.convert_redshift_to_distance(upperRedshiftLimit)
    upperMpcLimit = distanceDictionary["dl_mpc"]
    upperVolumeLimit = (4. / 3.) * np.pi * upperMpcLimit ** 3

    if lowerRedshiftLimit == 0.:
        lowerVolumeLimit = 0.
    else:
        distanceDictionary = da.convert_redshift_to_distance(
            lowerRedshiftLimit)
        lowerMpcLimit = distanceDictionary["dl_mpc"]
        lowerVolumeLimit = (4. / 3.) * np.pi * lowerMpcLimit ** 3

    volumeShell = upperVolumeLimit - lowerVolumeLimit

    # GENERATE A LIST OF RANDOM DISTANCES
    redshiftList = []
    for i in range(sampleNumber):
        randomVolume = lowerVolumeLimit + npr.random() * volumeShell
        randomDistance = (randomVolume * (3. / 4.) / np.pi) ** (1. / 3.)
        randomRedshift = da.convert_mpc_to_redshift(randomDistance)
        randomRedshift = closestNumber(randomRedshift, redshiftDistribution)
        # log.debug('randomDistance %s' % (randomDistance,))
        redshiftList.append(randomRedshift)

    redshiftArray = np.array(redshiftList)
    # log.info('redshiftArray %s' % (redshiftArray,))

    if plot:
        # FORCE SQUARE FIGURE AND SQUARE AXES LOOKS BETTER FOR POLAR
        fig = plt.figure(
            num=None,
            figsize=(8, 8),
            dpi=None,
            facecolor=None,
            edgecolor=None,
            frameon=True)

        ax = fig.add_axes(
            [0.1, 0.1, 0.8, 0.8],
            polar=True)

        thetaList = []
        twoPi = 2. * np.pi
        for i in range(sampleNumber):
            thetaList.append(twoPi * npr.random())
        thetaArray = np.array(thetaList)

        plt.scatter(
            thetaArray,
            redshiftArray,
            s=10,
            c='b',
            marker='o',
            cmap=None,
            norm=None,
            vmin=None,
            vmax=None,
            alpha=None,
            linewidths=None,
            edgecolor='w',
            verts=None,
            hold=None)

        title = "SN Redshift Distribution"
        plt.title(title)
        fileName = pathToOutputPlotDirectory + title.replace(" ", "_") + ".png"
        plt.savefig(fileName)
        plt.clf()  # clear figure

    return redshiftArray