0

回顾一些旧代码

<!--- RANDOMLY DECIDE IS THIS PERSONS A WINNER 1 IN 8 CHANCE--->
<cfset attributes.random_point = RandRange(1, 8)>

<cfif attributes.random_point eq 5>
  WINNER
<cfelse>
  You got nothing!
</cfif>

如何将其转换为小数赔率?从现在开始,我想用小数赔率来确定得到 x 的变化。例如,我有 1.10 或 1.11 的机会获得 x。

4

2 回答 2

2

如果我理解正确,那么我会将获胜的百分比定义为小数,然后依赖 Rand(),尽管这仍然感觉不理想

<cfscript>
    numChanceToWin = 0.15;  // <= this == winner == 15% chance to win
    numRandom = Rand(); // decimal from 0 to 1

    if (numRandom <= numChanceToWin ) {
        // Winner
    } else {
        // Loser
    }
<cfscript>

也可以通过设置numChanceToWin = 1/8;或什至与您的 1/8 定义一起使用if (numRandom/numChanceToWin <= 1) { // Winner

于 2012-04-17T14:52:24.520 回答
1

我只需将 attributes.random_point 设为 randrange(1,100)/100

<!--- RANDOMLY DECIDE IS THIS PERSONS A WINNER 1 IN 8 CHANCE--->
<cfset attributes.random_point = RandRange(0, 100)/100>

<cfif attributes.random_point lt 0.11>
  WINNER
<cfelse>
  You got nothing!
</cfif>
于 2012-04-17T14:46:36.177 回答