List Info

Thread: random subscripts




random subscripts
country flaguser name
United States
2008-03-19 11:34:47

As an absolute beginner at this language, i am stuck
on what is probably so simple i'll kick myself for not
seeing it.
I am learning (trying!) from Ellie Quigley's Perl by
Example 4th Ed.
One exercise asks the programmer to build a deck of
cards (easy!).
My hitch is in trying to get 10 cards at random.
I can get ten cards but, they are all the same card.
How does one get random subscripts with each iteration
of the loop?
Second half of prog:

foreach $i (1..10) {
$card = $deck[rand deck];
print "Card $i is the $card";;
}
What am I overlooking?

__________________________________________________________
Never miss a thing. Make Yahoo your home page.
http://www.yahoo.com/r/hs

__._,_.___
.

__,_._,___
Re: random subscripts
country flaguser name
United States
2008-03-19 11:36:59

>>&gt;>> "Donald" == Donald Korrecta < draktrax%40yahoo.com">draktraxyahoo.com> writes:

Donald&gt; I can get ten cards but, they are all the same card.

Your code wouldn't get the same card each time. Maybe you mean
&quot;sometimes I get the same card".

Unless somehow you have only one card in deck.

So perhaps you could post the code that has the behavior above,
or confirm the other two things I just said. Also show
how you initialize deck.

--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<; merlyn%40stonehenge.com">merlynstonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )