#!/usr/bin/python

f=open('/home/yanchao/test')

line=f.readline()

list=[]

def write_file(line):

    c=open('file','a')

    c.write(line)


while line:

    list.append(line)

    a=len(list)

    if a = 5000:

        for i in range(500):

            b=random.randint(5000)

            write_file(list[b])

        list=[]

    line=f.readline()

f.close()