def sample(self, seed: int, n_samples: int) -> TargetsLoader:
        """
        Sample from the targets loader, with replacement.

        Parameters
        ----------
        seed: int
            Random seed.
        n_samples: int
            Number of samples.

        Returns
        -------
        TargetsLoader
            A targets loader made of the sampled targets.
        """

        def fun():
            rng = np.random.default_rng(seed)
            count = 0

            while True:
                for targets in self:
                    if count == n_samples:
                        break
                    idx = rng.choice(2, targets.shape[0]).astype("bool")
                    targets = targets[idx]
                    if count + targets.shape[0] > n_samples:
                        targets = targets[: n_samples - count]
                    count += targets.shape[0]
                    if targets.shape[0] > 0:
                        yield targets

                if count == n_samples:
                    break

        return self.from_callable_iterable(fun)

        Sample from the targets loader, with replacement.

        Parameters
        ----------
        seed: int
            Random seed.
        n_samples: int
            Number of samples.

        Returns
        -------
        TargetsLoader
            A targets loader made of the sampled targets.
        
fortuna/data/loader/array_loaders.py