code: def get_random_sample(
      seq,
      n: int,
      stratify: bool = True,
      random_state: Optional[int] = None,
  ) -> list:
      random.seed(a=random_state)
      if stratify is True:
          grped = itertoolz.groupby(operator.itemgetter(1), seq)
          n_per_grp = max(int(round(n / len(grped))), 1)
          sample = list(
              itertoolz.concat(
                  random.sample(examples, min(len(examples), n_per_grp))
                  for examples in grped.values()
              )
          )
          random.shuffle(sample)
          return sample[:n]
      else:
          return random.sample(seq, min(len(seq), n))
  
imports: import argparse
  import collections
  import logging
  import operator
  import pathlib
  import random
  import statistics
  from functools import partial
  from typing import Optional
  import sklearn.model_selection
  from toolz import itertoolz
  import textacy.datasets
  import textacy.io
  import textacy.lang_id._datasets
  import textacy.preprocessing
label_desc: Use image node_id 5 for calling a global function with example usage: get_random_sample(seq, n, stratify, random_state) and returns: sample, random