Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 18th, 2005, 05:16 PM
Sean Carey
Guest
 
Posts: n/a
Default Python script that generates blob files

I am wondering if anyone knows of a python script or any other script
that will generate random files with random sizes that I can specify.
Thanks

Sean

  #2  
Old July 18th, 2005, 05:16 PM
Irmen de Jong
Guest
 
Posts: n/a
Default Re: Python script that generates blob files

Sean Carey wrote:[color=blue]
> I am wondering if anyone knows of a python script or any other script
> that will generate random files with random sizes that I can specify.[/color]

define "random files".

If you're on Linux or similar, just use the dd utility?

Otherwise something like this (where the contents of the file
is left blank):

f=open("filename","wb")
f.seek( desiredsize-1 )
f.write('\0')
f.close()

--Irmen
  #3  
Old July 18th, 2005, 05:16 PM
Paul Rubin
Guest
 
Posts: n/a
Default Re: Python script that generates blob files

"Sean Carey" <sean.carey@gmail.com> writes:[color=blue]
> I am wondering if anyone knows of a python script or any other script
> that will generate random files with random sizes that I can specify.[/color]

Python 2.4 should have an os.urandom function that gives you a random
character string of a size you specify. I'm not sure if that's what
you're asking.
  #4  
Old July 18th, 2005, 05:16 PM
Sean Carey
Guest
 
Posts: n/a
Default Re: Python script that generates blob files

hey
thanks for the reply. I think I can make this work the way I need it
too.

Cheers

Sean

  #5  
Old July 18th, 2005, 05:17 PM
Peter L Hansen
Guest
 
Posts: n/a
Default Re: Python script that generates blob files

Sean Carey wrote:[color=blue]
> I am wondering if anyone knows of a python script or any other script
> that will generate random files with random sizes that I can specify.[/color]

Presumably using the random module would help?

length = random.randint(0, 1000)
filename = 'test'

f = open(filename, 'wb')
i = 0
while i < length:
f.write(chr(random.randint(0, 255)))
f.close()

Slight variations could simplify this... use getopt or optparse
to retrieve command line arguments if you want to specify different
filenames or length ranges etc.

-Peter
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles