Reputation: 433
I was trying to design a contest where after user registration, the web page shows a button to play the game. By pressing the button, the page returns "you win" or "sorry, no win".
The problem is, how to give to the positive results less chances to be shown and not the 50/50. Say, it would be nice to have a 1 win out of 10 games.
I have set a mysql table for the user attempts. Every user has one chance only to play.
I cannot figure out the randomness mathematically speaking...
Any help is highly appreciated.
Thank you very much
Upvotes: 1
Views: 98
Reputation: 204854
You can use rand()
and then check for a specific result
select (cast(rand() * 10 as unsigned)) = 1
Step by step:
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
Upvotes: 2