code: def generate_random_sequences(
      vocab: Sequence[str], pattern: str, n: int, seed: int = 1
  ) -> MutableSequence[str]:
      """Generates random sequences.
  
      Args:
        vocab: the vocabulary for the sequences
        pattern: the pattern of the sequence. The length of the sequence will be
          inferred from the pattern.
        n: number of sequences to generate
        seed: random seed for numpy.random
  
      Returns:
        A sequence of different random sequences from the given vocabulary
      """
  
      def count_placeholder(pattern):
          return sum(
              [
                  x[1] is not None
                  for x in string.Formatter().parse(pattern)
              ]
          )
  
      length = count_placeholder(pattern)
      rng = np.random.RandomState(seed)
      vocab_size = len(vocab)
      if vocab_size**length <= n:
          # Generate all possible sequences of the length
          seq = np.array(list(itertools.product(vocab, repeat=length)))
          if vocab_size**length < n:
              print(
                  f"The total number of random sequences is less than n={n}.",
                  f"Will return {vocab_size**length} sequences only.",
              )
              n = vocab_size**length
      else:
          # Generate idx where each row contains the indices for one random sequence
          idx = np.empty((0, length), dtype=int)
          while idx.shape[0] < n:
              # Generate a new set of indices
              idx_new = rng.randint(vocab_size, size=(n, length))
              idx = np.concatenate(
                  [idx, idx_new], axis=0
              )  # Add to existing indices
              idx = np.unique(idx, axis=0)  # Remove duplicated indices
          idx = idx[:n]
          seq = np.array(vocab)[idx]
      # Join each row to get the sequence
      seq = np.apply_along_axis(
          lambda x: pattern.format(*list(x)), 1, seq
      )
      seq = seq[rng.permutation(n)]
      return list(seq)
  
file_path: privacy/tensorflow_privacy/privacy/privacy_tests/secret_sharer/generate_secrets.py
imports: import dataclasses
  import itertools
  import string
  from typing import Any, Dict, MutableSequence, Sequence
  import numpy
label_desc: Use image node_id 1 for calling a global function with example usage: generate_random_sequences(vocab, pattern, n, seed) and returns: list, sum