Your above code will delete files but it would be recoverable because of the working of file system. 
Concept: When the file is requested to be deleted, the OS does not remove the content of entire file because of performance reasons. OS perform these tasks:
- removes the file pointer (stored in MFT)
 
- OS announces reserved space as free of that specific file/folder
 
As suggested by @ernest_k, the only way to remove data is shredding except physical destruction.
If you are writing a program to do this task then your program should:
- Open a file
 
- Read it's content
 
- Generate random data
 
- Replace it with the original content
 
- At the end, you can remove the file
 
For multiple passes, you can repeat the above steps. I don't exactly remember but 
different standards are recommended in different standards like 1-pass, 3-pass, 6-pass.
Hope it helps! :)