input: Write a python function to generate a Markov chain from a given text and use it to generate random text of specified length.
  assert isinstance(generate_markov_chain("This is a test. This test is only a test."), dict)
  assert isinstance(generate_text(generate_markov_chain("This is a test. This test is only a test."), 10), str)
  assert len(generate_text(generate_markov_chain("Another example text for testing purposes."), 10).split()) == 10
output: import random
  
  def generate_markov_chain(text):
      words = text.split()
      markov_chain = {}
      
      for i in range(len(words) - 1):
          if words[i] in markov_chain:
              markov_chain[words[i]].append(words[i + 1])
          else:
              markov_chain[words[i]] = [words[i + 1]]
      
      if words[-1] not in markov_chain:
          markov_chain[words[-1]] = []
  
      return markov_chain
  
  def generate_text(markov_chain, length):
      if not markov_chain:
          return ""
      
      word = random.choice(list(markov_chain.keys()))
      generated_words = [word]
      
      for _ in range(length - 1):
          if word in markov_chain and markov_chain[word]:
              word = random.choice(markov_chain[word])
              generated_words.append(word)
          else:
              word = random.choice(list(markov_chain.keys()))
              generated_words.append(word)
      
      return " ".join(generated_words)