@app.route('/stream-bytes/<int:n>')
def stream_random_bytes(n):
 n = min(n, (100 * 1024))
 params = CaseInsensitiveDict(request.args.items())
 if ('seed' in params):
  random.seed(int(params['seed']))
 if ('chunk_size' in params):
  chunk_size = max(1, int(params['chunk_size']))
 else:
  chunk_size = (10 * 1024)
 def generate_bytes():
  chunks = bytearray()
  for i in xrange(n):
   chunks.append(random.randint(0, 255))
   if (len(chunks) == chunk_size):
    (yield bytes(chunks))
    chunks = bytearray()
  if chunks:
   (yield bytes(chunks))
 headers = {'Content-Type': 'application/octet-stream'}
 return Response(generate_bytes(), headers=headers)

@ app . route ( '/stream-bytes/<int:n>' ) def stream_random_bytes ( n ) : n = min ( n , ( 100 * 1024 ) ) params = CaseInsensitiveDict ( request . args . items ( ) ) if ( 'seed' in params ) : random . seed ( int ( params [ 'seed' ] ) ) if ( 'chunk_size' in params ) : chunk_size = max ( 1 , int ( params [ 'chunk_size' ] ) ) else : chunk_size = ( 10 * 1024 ) def generate_bytes ( ) : chunks = bytearray ( ) for i in xrange ( n ) : chunks . append ( random . randint ( 0 , 255 ) ) if ( len ( chunks ) == chunk_size ) : ( yield bytes ( chunks ) ) chunks = bytearray ( ) if chunks : ( yield bytes ( chunks ) ) headers = { 'Content-Type' : 'application/octet-stream' } return Response ( generate_bytes ( ) , headers = headers )
streams n random bytes generated with given seed .