Skip to main content
`Ctrl`+`K`

# skbio.stats.distance.randdm

skbio.stats.distance.randdm(num_objects, ids=None, constructor=None, random_fn=None)

  Generate a distance matrix populated with random distances.

  Using the default `random_fn`, distances are randomly drawn from a uniform distribution over `[0, 1)`. Regardless of `random_fn`, the resulting distance matrix is guaranteed to be symmetric and hollow.

  Parameters:
    num_objects int

      The number of objects in the resulting distance matrix. For example, if `num_objects` is 3, a 3x3 distance matrix will be returned.

    ids sequence of str or None, optional

      A sequence of strings to be used as IDs. `len(ids)` must be equal to `num_objects`. If not provided, IDs will be monotonically-increasing integers cast as strings (numbering starts at 1). For example, `('1', '2', '3')`.

    constructor type, optional

      `PairwiseMatrix` or its subclass to use when creating the random distance matrix. The returned matrix will be of this type. By default, a `DistanceMatrix` instance will be returned.

    random_fn int, np.random.Generator or callable, optional

      Function for generating random values. It must accept (n_rows, n_columns) and return a 2D array of float-like. Default is the `random` method of a NumPy random generator. If an integer is provided, a random generator will be constructed using this number as the seed.

      Changed in version 0.6.3: Switched to NumPy’s new random generator. Can accept a random seed or random generator instance. The function takes one tuple parameter instead of two separate parameters.

  Returns:
    PairwiseMatrix

      `PairwiseMatrix` (or subclass) instance of random distances. Type depends on `constructor`.

  See also

  `numpy.random.Generator.random`