Re: performance of script to write very long lines of random chars

2013-04-11 Thread Chris Angelico
On Thu, Apr 11, 2013 at 10:05 PM, Oscar Benjamin wrote: > On 11 April 2013 11:50, Steven D'Aprano > wrote: >> Some (most?) modern operating systems provide a cryptographically strong >> source of non-deterministic randomness. The non-deterministic part comes >> from external "stuff", which is cal

Re: performance of script to write very long lines of random chars

2013-04-11 Thread Robert Kern
On 2013-04-11 17:35, Oscar Benjamin wrote: On 11 April 2013 11:50, Steven D'Aprano wrote: On Thu, 11 Apr 2013 10:47:43 +0100, Oscar Benjamin wrote: On 11 April 2013 08:47, Steven D'Aprano wrote: One thing to be aware of: urandom may run out of entropy, and then it will slow down a lot. If

Re: performance of script to write very long lines of random chars

2013-04-11 Thread Oscar Benjamin
On 11 April 2013 11:50, Steven D'Aprano wrote: > On Thu, 11 Apr 2013 10:47:43 +0100, Oscar Benjamin wrote: > >> On 11 April 2013 08:47, Steven D'Aprano >> wrote: >> >>> One thing to be aware of: urandom may run out of entropy, and then it >>> will slow down a lot. If you don't care about cryptogr

Re: performance of script to write very long lines of random chars

2013-04-11 Thread Robert Kern
On 2013-04-11 16:20, Steven D'Aprano wrote: On Thu, 11 Apr 2013 10:47:43 +0100, Oscar Benjamin wrote: On 11 April 2013 08:47, Steven D'Aprano wrote: One thing to be aware of: urandom may run out of entropy, and then it will slow down a lot. If you don't care about cryptographic randomness, y

Re: performance of script to write very long lines of random chars

2013-04-11 Thread Steven D'Aprano
On Thu, 11 Apr 2013 10:47:43 +0100, Oscar Benjamin wrote: > On 11 April 2013 08:47, Steven D'Aprano > wrote: > >> One thing to be aware of: urandom may run out of entropy, and then it >> will slow down a lot. If you don't care about cryptographic randomness, >> you could use this instead: > > R

Re: performance of script to write very long lines of random chars

2013-04-11 Thread Oscar Benjamin
On 11 April 2013 08:47, Steven D'Aprano wrote: > One thing to be aware of: urandom may run out of entropy, and then it > will slow down a lot. If you don't care about cryptographic randomness, > you could use this instead: Reading this I'm realising that I don't really know what os.urandom is. H

Re: performance of script to write very long lines of random chars

2013-04-11 Thread Oscar Benjamin
On 11 April 2013 02:21, gry wrote: > Dear pythonistas, >I am writing a tiny utility to produce a file consisting of a > specified number of lines of a given length of random ascii > characters. I am hoping to find a more time and memory efficient way, > that is still fairly simple clear, and

Re: performance of script to write very long lines of random chars

2013-04-11 Thread Steven D'Aprano
On Wed, 10 Apr 2013 18:21:51 -0700, gry wrote: > Dear pythonistas, >I am writing a tiny utility to produce a file consisting of a > specified number of lines of a given length of random ascii characters. > I am hoping to find a more time and memory efficient way, that is still > fairly simple

Re: performance of script to write very long lines of random chars

2013-04-10 Thread Chris Angelico
On Thu, Apr 11, 2013 at 3:33 PM, Steven D'Aprano wrote: > I was originally going to write that using the base64 module would > introduce bias into the random strings, but after a little investigation, > I don't think it does. Assuming that os.urandom() returns bytes with perfectly fair distributi

Re: performance of script to write very long lines of random chars

2013-04-10 Thread Steven D'Aprano
On Thu, 11 Apr 2013 11:45:31 +1000, Chris Angelico wrote: > On Thu, Apr 11, 2013 at 11:21 AM, gry wrote: >> avail_chrs = >> '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%& >> \'()*+,-./:;<=>?@[\\]^_`{}' > > Is this exact set of characters a requirement? For instance, would

Re: performance of script to write very long lines of random chars

2013-04-10 Thread Chris Angelico
On Thu, Apr 11, 2013 at 12:40 PM, gry wrote: > Appealing idea, but it's slower than the array solution: 5min 13 > secs. vs 4min 30sec for the array: > > for l in range(rows): > for i in xrange(nchars): > stdout.write(random.choice(avail_chrs)) > stdout.write('\n') > > > os.urandom

Re: performance of script to write very long lines of random chars

2013-04-10 Thread MRAB
On 11/04/2013 02:21, gry wrote: Dear pythonistas, I am writing a tiny utility to produce a file consisting of a specified number of lines of a given length of random ascii characters. I am hoping to find a more time and memory efficient way, that is still fairly simple clear, and _pythonic_.

Re: performance of script to write very long lines of random chars

2013-04-10 Thread gry
On Apr 10, 9:52 pm, Michael Torrie wrote: > On 04/10/2013 07:21 PM, gry wrote: > > > > > > > > > > > from sys import stdout > > from array import array > > import random > > nchars = 3200 > > rows = 10 > > avail_chrs = > > '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%& >

Re: performance of script to write very long lines of random chars

2013-04-10 Thread Michael Torrie
On 04/10/2013 07:21 PM, gry wrote: > from sys import stdout > from array import array > import random > nchars = 3200 > rows = 10 > avail_chrs = > '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%& > \'()*+,-./:;<=>?@[\\]^_`{}' > a = array('c', 'X' * nchars) > > for l in ran

Re: performance of script to write very long lines of random chars

2013-04-10 Thread Chris Angelico
On Thu, Apr 11, 2013 at 11:21 AM, gry wrote: > avail_chrs = > '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%& > \'()*+,-./:;<=>?@[\\]^_`{}' Is this exact set of characters a requirement? For instance, would it be acceptable to instead use this set of characters? avail_chrs

performance of script to write very long lines of random chars

2013-04-10 Thread gry
Dear pythonistas, I am writing a tiny utility to produce a file consisting of a specified number of lines of a given length of random ascii characters. I am hoping to find a more time and memory efficient way, that is still fairly simple clear, and _pythonic_. I would like to have something th