<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def random_subset_by_duration(self, relative_duration, balance_labels=False, label_list_ids=None):
 """ Create a subview of random utterances with a approximate duration relative to the full corpus. Random utterances are selected so that the sum of all utterance durations equals to the relative duration of the full corpus. Args: relative_duration (float):
 A value between 0 and 1. (e.g. 0.5 will create a subset with approximately 50% of the full corpus duration) balance_labels (bool):
 If True, the labels of the selected utterances are balanced as far as possible. So the count/duration of every label within the subset is equal. label_list_ids (list):
 List of label-list ids. If none is given, all label-lists are considered for balancing. Otherwise only the ones that are in the list are considered. Returns: Subview: The subview representing the subset. """

        total_duration = self.corpus.total_duration
        subset_duration = relative_duration * total_duration
        utterance_durations = {utt_idx: utt.duration for utt_idx, utt in self.corpus.utterances.items()}

        if balance_labels:
            all_label_values = self.corpus.all_label_values(label_list_ids=label_list_ids)

            label_durations = {}
            for utt_idx, utt in self.corpus.utterances.items():
                label_durations[utt_idx] = utt.label_total_duration(label_list_ids)

            subset_utterance_ids = utils.select_balanced_subset(label_durations,
                                                                subset_duration,
                                                                list(all_label_values),
                                                                select_count_values=utterance_durations,
                                                                seed=self.rand.random())

        else:
            dummy_weights = {utt_idx: {'w': 1} for utt_idx in self.corpus.utterances.keys()}
            subset_utterance_ids = utils.select_balanced_subset(dummy_weights,
                                                                subset_duration,
                                                                ['w'],
                                                                select_count_values=utterance_durations,
                                                                seed=self.rand.random())

        filter = subview.MatchingUtteranceIdxFilter(utterance_idxs=set(subset_utterance_ids))
        return subview.Subview(self.corpus, filter_criteria=[filter])