2017-04-15 34 views
1

我試圖設計一個比賽,用戶註冊後,網頁顯示一個按鈕來玩遊戲。按下按鈕,頁面會返回「您贏」或「抱歉,不贏」。php在獲獎競賽中獲得積極的隨機響應

的問題是,如何給予積極成果顯示機會少,而不是50/50。比方說,在10場比賽中有1勝是一件好事。

我已經爲用戶嘗試設置了一個mysql表。每個用戶只有一次機會玩。

我想不通數學上講隨機性...

任何幫助,高度讚賞。

非常感謝您

回答

2

您可以使用rand(),然後檢查是否有特定的結果

select (cast(rand() * 10 as unsigned)) = 1 

循序漸進:

select rand()         returns a number between 0.0 and 1.0 
select cast((rand() * 10) as unsigned)  returns a number between 0 and 9 
select cast((rand() * 10) as unsigned) = 1 checks if the result was 1 which is a win 
               but it is a loose for all random numbers != 1 
+0

感謝您的想法。我會試一試。這可能是正確的路徑 – Aptivus

+0

,這是完美的。我已經測試了幾次,效果很好。非常感謝你 – Aptivus