Random Number Question
From: Paul C-T (paulcharltonthomson_at_hotmail.com)
Date: 07/30/04
- Next message: Al C.: "Re: PHP with sybase or postgresql"
- Previous message: Robin H. Johnson: "Getting an OpenSSL public key in PEM form, from a private key or a certificate."
- Next in thread: steve: "Re: Random Number Question"
- Reply: steve: "Re: Random Number Question"
- Reply: Gordon Burditt: "Re: Random Number Question"
- Reply: Paul C-T: "Re: Random Number Question"
- Reply: Pjotr Wedersteers: "Re: Random Number Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: Al C.: "Re: PHP with sybase or postgresql"
- Previous message: Robin H. Johnson: "Getting an OpenSSL public key in PEM form, from a private key or a certificate."
- Next in thread: steve: "Re: Random Number Question"
- Reply: steve: "Re: Random Number Question"
- Reply: Gordon Burditt: "Re: Random Number Question"
- Reply: Paul C-T: "Re: Random Number Question"
- Reply: Pjotr Wedersteers: "Re: Random Number Question"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|