Random Numbers in Perl

Nathan Saper natedog@well.com
Tue, 24 Oct 2000 22:47:48 -0700


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, Oct 23, 2000 at 05:17:03AM -0700, Jason wrote:
> Nathan Saper wrote:
> > Here's one for you Perl gurus out there:
> > 
> > In a Perl app I'm trying to write, I want to be able to create random
> > hex integers $bits bits long, where $bits is a user-defined variable.
> > The randomness of the numbers needs to be as good as possible, because
> > it would be used in a crypto app.
> > 
> > Any ideas?
> 
> Do it in C, and have the perl script take the output.. Perl isnt
> really fast enough for this type of thing.
> 

> I have this sinking sensation, however, that your wanting to do this
> for something that will be platform independant, and run on a
> webserver... which makes the above impossible. Hmmm..
> 

Precisely.

> Anyways, heres a standalone application with a hard-coded number of
> bits... it at least works well enough that you can call it from a bash
> script to define a variable or some such.. 
> 
> The weird code at the front of the program (the xbits, or extra bits,
> stuff) handles the event that the number of bits is NOT a multiple of
> four.. in these cases, the digit first printed must be the one with
> the limited range (0-7, 0-3, or 0-1) depending on the number of extra
> bits.
> 

Thanks for the code.  I'm gonna try to use some of those ideas in my script.

- --
Nathan Saper (natedog@well.com) | http://www.well.com/user/natedog/
GnuPG (ElGamal/DSA): 0x9AD0F382 | PGP 2.x (RSA): 0x386C4B91
Standard PGP & PGP/MIME OK      | AOL Instant Messenger: linuxfu
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.4 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.5 and Gnu Privacy Guard <http://www.gnupg.org/>

iD8DBQE59nPS2FWyBZrQ84IRAllkAKCLJVAuGRq15+943kHCteB1FpCz8gCfTPoo
iBPr0D6lBy0h4sKOixsLzv8=
=rM/T
-----END PGP SIGNATURE-----