Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Jun 2003 17:32:35 +0100
From:      Matthew Seaman <m.seaman@infracaninophile.co.uk>
To:        "Jack L. Stone" <jackstone@sage-one.net>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Running a rand or random script
Message-ID:  <20030616163235.GB33582@happy-idiot-talk.infracaninophile.co.uk>
In-Reply-To: <3.0.5.32.20030616111517.0137e538@sage-one.net>
References:  <3.0.5.32.20030616111517.0137e538@sage-one.net>

next in thread | previous in thread | raw e-mail | index | archive | help

--tsOsTdHNUZQcU9Ye
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Mon, Jun 16, 2003 at 11:15:17AM -0500, Jack L. Stone wrote:
> I need to run a script, perhaps using FBSD's 'rand' or 'random' command (=
or
> any other) that will generate one single 5-digit number 'at random' betwe=
en
> 00001-99999
>=20
> Anyone have thoughts on how to do this....??

    perl -e 'printf "%0.5d\n", int(rand(99999) + 1);'

Assuming that range is inclusive.

	Cheers,

	Matthew

Nb. Don't use srand() explicitly --- perl will auto-seed the PRNG from
/dev/urandom if left to it's own devices.

--=20
Dr Matthew J Seaman MA, D.Phil.                       26 The Paddocks
                                                      Savill Way
PGP: http://www.infracaninophile.co.uk/pgpkey         Marlow
Tel: +44 1628 476614                                  Bucks., SL7 1TH UK

--tsOsTdHNUZQcU9Ye
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (FreeBSD)

iD8DBQE+7fEjdtESqEQa7a0RAgs4AJ9JuF8rU8mKF3tgrsuNnqgfr5cYPwCdF7FK
vFSr/G+kM5LeO/WBe29Y3Qk=
=+bwE
-----END PGP SIGNATURE-----

--tsOsTdHNUZQcU9Ye--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030616163235.GB33582>