随机数问题 [英] Random Number Question

查看:99
本文介绍了随机数问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有没有办法重复一组代码,直到某个if语句满足

。如果它然后退出循环,如果不重复代码?


说我想用PHP编写一个纸牌游戏应用程序,我想选择一个
$ b来自牌组的$ b卡$ card1 = rand(1,52);得到我的第一张卡片。


我需要记录哪张卡已经发出,所以我有一个变量$ dealing

以字符串52开头零。我将$ / $ $ $ $ $ $字符串中的$ card1的位置更新为1。


因此,黑桃5中的$ deal =&000010000000000 ... ...


我想选择另一张卡,所以我使用$ card2 = rand(1,52);然后需要

检查它是否已被处理。如果$ dealing中的位置为1,那么我需要重复随机数代码,直到它为0时我可以更新它

到1然后继续...


或者有更好的办法做这类事情吗?


一如既往的帮助,赞赏。 />

保罗。

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.

推荐答案

card1 = rand(1,52);得到我的第一张卡片。


我需要记录哪张卡已被处理,所以我有一个变量
card1 = rand(1,52); gets me my first card.

I need to record which card has been dealt so I have a variable


处理了

以52个零的字符串开头。我在
dealt which
starts out as a string of 52 zeros. I update the position of

中更新了


card1的位置

这篇关于随机数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆