On Wed, Mar 24, 2010 at 5:15 AM, Philip Potter <philip.g.pot...@gmail.com> wrote: > On 24 March 2010 00:56, Eric Veith1 <eric.ve...@de.ibm.com> wrote: >> Sam <p...@net153.net> wrote on 03/23/2010 11:18:11 PM: >>> Could you use a file of random data? You can create one of those really >>> easy: dd if=/dev/urandom of=ranfile bs=9999 >> >> Theoretically, yes, of course I could just try to create an arbitrary >> sized file from /dev/urandom via dd. I hoped there would be an equally >> both fast and elegant solution possible as with the C approach (malloc >> without init). Bob's idea of just reading and piping files from /bin or >> /usr/bin was also a good idea. >> >> Well, if there's no... "more elegant" solution, I'll happily go with what >> has been offered. (Note the " around "more elegant"!) > > I would say both of the offered solutions are more elegant than using > uninitialised malloc()ed memory. You can't rely on malloc to offer you > known data, but you *also* can't rely on it to give you sufficiently > random data. The /bin option also has the advantage (or disadvantage, > depending on application) of being deterministic. > > I note that a quick search on CPAN for "urandom" turns up > String::Urandom as a more Perlish way to access /dev/urandom. I'm not > sure how much it gains you: given that you still depend on > /dev/urandom being present, you might as well make it explicit. >
I agree. the malloc hack is decidedly unelegant, and probably unportable. My thought would be to fork a subprocess to read from /dev/urandom, possibly using String::Urandom, and act as a buffer. /dev/urandom may be too slow for on-demand generation in this case, but it's not *that* slow. If you fork your collector as the first thing in your script, by the time you finish the rest of your setup--loading modules, establishing connections, etc.--you should have enough randomness in the buffer to start sending while you read more into the buffer. A little trial and error should tell you how much data you need to preload. Another tactic I've used for similar projects on Linux is to read bits from a raw audio device. That may or may not be an option on your platform. It's not truly random--it's predictable if you know the input--but it's a bottomless, real-time well of fairly unordered bits. HTH, -- jay -------------------------------------------------- This email and attachment(s): [ ] blogable; [ x ] ask first; [ ] private and confidential daggerquill [at] gmail [dot] com http://www.tuaw.com http://www.downloadsquad.com http://www.engatiki.org values of β will give rise to dom! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/