code: def random(args):
      
      from random import sample
  
      p = OptionParser(random.__doc__)
      opts, args = p.parse_args(args)
  
      if len(args) != 2:
          sys.exit(not p.print_help())
  
      fastafile, N = args
      N = int(N)
      assert N > 0
  
      f = Fasta(fastafile)
      fw = must_open("stdout", "w")
  
      for key in sample(f.keys(), N):
          rec = f[key]
          SeqIO.write([rec], fw, "fasta")
  
      fw.close()
docs: %prog random fasta 100 > random100.fasta
  
      Take number of records randomly from fasta