查看一些旧代码
<!--- 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。
答案 0 :(得分: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;
甚至if (numRandom/numChanceToWin <= 1) { // Winner
答案 1 :(得分: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>