Random Number Question

From: Paul C-T (paulcharltonthomson_at_hotmail.com)
Date: 07/30/04


Date: Fri, 30 Jul 2004 03:41:00 +0100

Hi,

Is there a way to repeat a set of code until a certain if statement is
satisfied. If it is then to exit the loop and if not repeat the code?

Say I want to write a card game application in PHP and I want to chose a
card from the deck $card1 = rand(1,52); gets me my first card.

I need to record which card has been dealt so I have a variable $dealt which
starts out as a string of 52 zeros. I update the position of $card1 in the
$dealt string to "1".

So the 5 of Spades makes $dealt = "000010000000000 ..."

I want to choose another card so I use $card2 = rand(1,52); and then need to
check if it has already been dealt. If the position in $dealt is a 1 then I
need to repeat the random number code until it is a 0 when I can update it
to a 1 and move on ...

Or is there a better way of doing this sort of thing ??

Help, as always, appreciated.

Paul.



Relevant Pages

  • Re: Random Number Question
    ... If it is then to exit the loop and if not repeat the code? ... > Say I want to write a card game application in PHP and I want to chose a ... > I need to record which card has been dealt so I have a variable $dealt which ...
    (comp.lang.php)
  • I "killfiled" Mason too! But he wont stay dead!
    ... probability is true ONLY when the first card has yet to be dealt from the deck. ...
    (rec.gambling.craps)
  • Re: BS777 predicts ____
    ... Cards dealt from a deck without replacement are a classic example of dependent ... A standard deck of 52 playing cards is fairly shuffled. ... probability is true ONLY when the first card has yet to be dealt from the deck. ...
    (rec.gambling.craps)
  • Re: BS777 predicts ____
    ... Don't forget the strategy card. ... Cards dealt from a deck without replacement are a classic example of dependent ... A standard deck of 52 playing cards is fairly shuffled. ... probability is true ONLY when the first card has yet to be dealt from the deck. ...
    (rec.gambling.craps)
  • Re: Eternal or not?
    ... A relaxed NRA: ... A minion cannot repeat the same action more than 10 times in a single turn (note ... action with the same action card or via the same card in play ...
    (rec.games.trading-cards.jyhad)