Re: Running a rand or random script
Whoops, did too much C++ programming these days, in C this should really be: #include #include int main (int argc, char *argv[]) { unsigned int r; srandomdev(); /* use this on non-BSD systems: srandom(time (0)); */ r = random () % 9 +1; printf ("%d\n", r); return r; } ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Running a rand or random script
At 05:32 PM 6.16.2003 +0100, Matthew Seaman wrote: >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' between >> 1-9 >> >> Anyone have thoughts on how to do this?? > >perl -e 'printf "%0.5d\n", int(rand(9) + 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. > >-- >Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks > Savill Way Matthew: Your one-liner is just exactly what I needed. THANKS! Best regards, Jack L. Stone, Administrator SageOne Net http://www.sage-one.net [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
RE: Running a rand or random script
jot -r 5 0 9 | rs -g 0 5 -- Barry Byrne, IT Manager, WBT Systems, Block 2, Harcourt Centre Harcourt Street, Dublin 2, Ireland > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] Behalf Of Jack L. Stone > Sent: 16 June 2003 17:15 > To: [EMAIL PROTECTED] > Subject: Running a rand or random script > > > 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' between > 1-9 > > Anyone have thoughts on how to do this?? > > Many thanks for any suggestions. > > Best regards, > Jack L. Stone, > Administrator > > SageOne Net > http://www.sage-one.net > [EMAIL PROTECTED] > ___ > [EMAIL PROTECTED] mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to > "[EMAIL PROTECTED]" ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Running a rand or random script
Hi, > 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' between > 1-9 > > Anyone have thoughts on how to do this?? Don't know about a shell way to do this, but what about this tiny C program (compile and link with gcc -c -o r.o && gcc -or r.o) #include #include int main (int argc, char *argv[]) { srandomdev(); /* use this on non-BSD systems: srandom(time (0)); */ unsigned int r = random () % 9 +1; printf ("%d\n", r); return r; } Cheers, Simon ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"
Re: Running a rand or random script
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' between > 1-9 > > Anyone have thoughts on how to do this?? perl -e 'printf "%0.5d\n", int(rand(9) + 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. -- 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 pgp0.pgp Description: PGP signature
Running a rand or random script
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' between 1-9 Anyone have thoughts on how to do this?? Many thanks for any suggestions. Best regards, Jack L. Stone, Administrator SageOne Net http://www.sage-one.net [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "[EMAIL PROTECTED]"