input: Write a function to generate a Markov chain given a text input. The function should split the text into words and build a chain where each word maps to possible following words and their frequencies. Finally, the function should generate a new text of 100 words based on the Markov chain. If the Markov chain terminates before 100 words are generated, the function should return the generated text as is.
  assert generateMarkov('Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, `and what is the use of a book,' thought Alice `without pictures or conversation?') != None
  assert len(generateMarkov('Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, `and what is the use of a book,' thought Alice `without pictures or conversation?').split()) <= 100
output: 
  def generateMarkov(text):
      from collections import defaultdict
      import random
      
      words = text.split()
      chain = defaultdict(lambda: defaultdict(int))
      
      for i in range(len(words) - 1):
          chain[words[i]][words[i + 1]] += 1
      
      current_word = random.choice(words)
      result = [current_word]
      
      while len(result) < 100:
          if not chain[current_word]:
              break
          next_word = random.choices(list(chain[current_word].keys()), weights=chain[current_word].values(), k=1)[0]
          result.append(next_word)
          current_word = next_word
      
      return ' '.join(result)
  