code: def random_windows(
      cls,
      corpus: TimeSeriesCorpus,
      n_windows: int,
      horizon: int,
      context: Optional[int] = None,
      gap: int = 0,
      shift: int = 1,
      cold_start: bool = False,
      favor_recent: bool = False,
  ):
      all_windows = []
      weights = []
      for scope_id, series in tqdm(
          enumerate(corpus),
          desc="Building dataset",
          total=len(corpus),
      ):
          stop = len(series) - horizon
          start = gap
          if context is not None and not cold_start:
              start = start + context
          else:
              start = start + 1
          windows = [
              (scope_id, index) for index in range(stop, start, -shift)
          ]
          all_windows.extend(windows)
          if favor_recent:
              weights.extend(range(stop, start, -shift))
          else:
              weights.extend([1.0] * len(windows))
      weights = np.array(weights) / np.sum(weights)
      np.random.seed(42)
      windows_idx = np.random.choice(
          len(all_windows),
          size=n_windows,
          replace=len(all_windows) < n_windows,
          p=weights,
      )
      windows = [all_windows[i] for i in windows_idx]
      return cls(
          corpus,
          windows=windows,
          horizon=horizon,
          context=context,
          gap=gap,
      )
  
file_path: gluonts/src/gluonts/nursery/daf/tslib/dataset/forecasting.py
imports: from __future__ import annotations
  from typing import List, Tuple, Dict, Optional
  import numpy
  from tqdm import tqdm
  from .timeseries import TimeSeries, TimeSeriesCorpus
  from .windows import WindowsDataset
label_desc: Use image node_id 5 for calling the ForecastingDataset obj's underlying member method code with example usage: obj.random_windows(cls, corpus, n_windows, horizon, context, gap, shift, cold_start, favor_recent) and returns: cls