Q:

Generate file of given size

For test purposes I'd like to get file of given size filled with random data. 
So I have two questions:

How to efficiently generate file of given size in Android? 

is RandomAccessFile sufficient method? ( see Create file with given size in Java)

How to efficiently fill the file with random data ? 

What is the best source (ideally compatible back to v7) of random bytes? 
Is it necessary, because the file would contain data previously written in allocated harddisk space? 

A:

You just create the file and fill it with the size you want.  You don't 'set the size'.  If you create a file and put 1 kilobytes of stuff into it the file will be 1 kilobyte (*slightly larger actually). 
So just create a file, and use whatever file write routine to output bytes which you can create with (byte)(random()*510 - 255) in a loop for however many bytes large you want the file to be.  Since this is java and you may want to use print to output to the file, you have to use (char)(Math.random()*510 - 255) otherwise it will print the string "65" instead of "A"

