[16105] in Perl-Users-Digest
Perl-Users Digest, Issue: 3517 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 30 00:06:01 2000
Date: Thu, 29 Jun 2000 21:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <962337911-v9-i3517@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 29 Jun 2000 Volume: 9 Number: 3517
Today's topics:
Re: $_ and @_ use? <o1technospam@skyenet.nospam.net>
Re: ***Do not use this code!*** Re: Perl Help Please! <elaine@chaos.wustl.edu>
Re: ***Do not use this code!*** Re: Perl Help Please! <elaine@chaos.wustl.edu>
Re: a large amount of unique numbers in an efficient wa <srmalloy@home.com>
Re: a large amount of unique numbers in an efficient wa (Abigail)
Re: a large amount of unique numbers in an efficient wa (Abigail)
Arrakis & Perl <juanlosa@arrakis.es>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 29 Jun 2000 22:49:09 -0500
From: "Jim Kauzlarich" <o1technospam@skyenet.nospam.net>
Subject: Re: $_ and @_ use?
Message-Id: <2GU65.411$JZ4.1696@newsfeed.slurp.net>
"Michael Carman" <mjcarman@home.com> wrote in message
news:395B516C.3A943FA6@home.com...
> programmers. If you're writing code that somebody else is going to have
> to maintain, try to err on the side of verbosity and clarity instead of
> obfuscating things by playing Perl golf.
>
> -mjc
Ok, I know I'm going to open myself up here, though in my voluminous (2)
postings I've never claimed to be any thing but a !(Perl Guru).
What is "Perl golf"? I assume it has something to do with randomly hacking
your way to the goal. I've heard the term at least twice now and I'm
curious.
JMK
------------------------------
Date: Fri, 30 Jun 2000 03:34:05 GMT
From: Elaine -HFB- Ashton <elaine@chaos.wustl.edu>
Subject: Re: ***Do not use this code!*** Re: Perl Help Please!
Message-Id: <395C152C.CFA66705@chaos.wustl.edu>
"Godzilla!" wrote:
> > > To the poster of said code: *Submit a cancellation immediately*,
> > > and we'll hope for the best.
>
> Jeesshh... take a chill pill dude before you suffer
> a cardiac arrest or suffer intense flatulence.
Well, you know, if they don't behave like it's the end of the world and
the most important thing on Earth they might wake up and find out there
there is no meaning at all :)
GIGO.
e.
------------------------------
Date: Fri, 30 Jun 2000 03:35:32 GMT
From: Elaine -HFB- Ashton <elaine@chaos.wustl.edu>
Subject: Re: ***Do not use this code!*** Re: Perl Help Please!
Message-Id: <395C1583.8003A5DE@chaos.wustl.edu>
"Randal L. Schwartz" wrote:
> OP: "I need something to light this cigarette."
> You: "Here, take this flamethrower. It does the job."
>
> What you did, sir, was unethical. Please don't do it again.
<dr. evil> RiiiiiggggggT</dr. evil>
e.
------------------------------
Date: Fri, 30 Jun 2000 01:28:12 GMT
From: Sean Malloy <srmalloy@home.com>
Subject: Re: a large amount of unique numbers in an efficient way?
Message-Id: <yvZbOSqFSJ1xn+i2FKnMz=qlM8Pu@4ax.com>
Andrew Collington <aahz@writeme.com> wrote:
>What would be the most efficient way to generate a large array of random
>numbers, from, say 1000 to 9999?
>
>I could get a random number and check to see if it's above 1000, if it's
>not then create another and keep doing this till I have a number above
>1000. Then I would have to check through the array of already created
>numbers for a match, and repeat process if there is a match. I would
>have to do this 1500 times or more (having to have 1500 unique numbers
>;)
>
>This seems to me to be very inefficient so I was wondering if anyone
>knew a better way to do it?
First, if you're generating random numbers between X and Y, you
generate a number between 0 and (Y-X), and then add X to it; that
automatically gives you a number in the range you want without having
to generate extra numbers.
The rest of your problem can be defined as 'selection without
replacement', and such an algorithm should be in any good college text
on algorithms and programming. The most common use for such an
algorithm is for programs that randomize a known set of items, such as
for card games like blackjack or poker.
--
Sean R. Malloy | American Non Sequitur
Naval Medical Center | Society
San Diego, CA 92134-5000 |
srmalloy@home.net | "We may not make sense,
srmalloy@nmcsd.med.navy.mil | but we do like pizza"
FORMAL NOTICE: unsolicited commercial email will be read
at a charge of $500 per item. Receipt of such email shall
be considered to constitute acceptance of contract, and
will be billed immediately.
------------------------------
Date: 29 Jun 2000 22:14:46 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: a large amount of unique numbers in an efficient way?
Message-Id: <slrn8lo1me.ka1.abigail@alexandra.delanet.com>
Andrew Collington (aahz@writeme.com) wrote on MMCDXCIV September MCMXCIII
in <URL:news:395BB828.B41AEACD@writeme.com>:
.. Hi there,
..
.. What would be the most efficient way to generate a large array of random
.. numbers, from, say 1000 to 9999?
Pick a number from 0 to 8999. Add 1000. Repeat till you have the array
filled.
.. I could get a random number and check to see if it's above 1000, if it's
.. not then create another and keep doing this till I have a number above
.. 1000. Then I would have to check through the array of already created
.. numbers for a match, and repeat process if there is a match. I would
.. have to do this 1500 times or more (having to have 1500 unique numbers
.. ;)
Ah, now you change the problem.
.. This seems to me to be very inefficient so I was wondering if anyone
.. knew a better way to do it?
Take an array containing numbers 1000 to 9999, inclusive. Shuffle.
Take first 1500 elements.
And you can implement the obvious improvement.
Abigail
--
perl -weprint\<\<EOT\; -eJust -eanother -ePerl -eHacker -eEOT
------------------------------
Date: 29 Jun 2000 22:17:00 EDT
From: abigail@delanet.com (Abigail)
Subject: Re: a large amount of unique numbers in an efficient way?
Message-Id: <slrn8lo1qm.ka1.abigail@alexandra.delanet.com>
Stephen Kloder (stephen.kloder@gtri.gatech.edu) wrote on MMCDXCIV
September MCMXCIII in <URL:news:395BBEEE.9F304A73@gtri.gatech.edu>:
@@ Andrew Collington wrote:
@@
@@ > Hi there,
@@ >
@@ > What would be the most efficient way to generate a large array of random
@@ > numbers, from, say 1000 to 9999?
@@ >
@@
@@ Here's the quickest method I can think of:
@@ 1) Generate a random number < 9000
@@ 2) Add 1000 to it
@@ 3) Put it in a hash
@@ 4) repeat steps 1-3 until there are 1500 keys in the hash
@@
@@ On average, this method required 1640 iterations to obtain 1500 distinct
@@ random numbers. This took about a second on my machine (a P133).
Part of being an correct algorithm implies garanteed termination.
The above algorithm doesn't have that.
Abigail
--
perl -e '$_ = q *4a75737420616e6f74686572205065726c204861636b65720a*;
for ($*=******;$**=******;$**=******) {$**=*******s*..*qq}
print chr 0x$& and q
qq}*excess********}'
------------------------------
Date: Fri, 30 Jun 2000 01:22:15 GMT
From: "news.teleline.es" <juanlosa@arrakis.es>
Subject: Arrakis & Perl
Message-Id: <bDS65.6504$Bg2.25323@telenews.teleline.es>
Hello,
now Arrakis.com don't allow Perl cgi for all the new users.
:)
--
--
juanlosa@arrakis.es
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 3517
**************************************