Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
Picking a reward amount based on odds
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Ecko" data-source="post: 375427" data-attributes="member: 24874"><p>Your method is 33.33% chance for any. The way [USER=9520]@Wess[/USER] described would be how you get the proper odds:</p><p></p><p>[php]</p><p><?php</p><p>$rand = rand(1, 100);</p><p>$amount = array("50", "100", "250");</p><p></p><p>if($rand <= '70') {</p><p>echo "You win $amount[0]";</p><p></p><p>} elseif ($rand > '70' && $rand < '90') {</p><p> echo "You win $amount[1]";</p><p></p><p>} else {</p><p> echo "You win $amount[2]";</p><p>}</p><p>[/php]</p><p></p><p>Don't mind the sloppiness, I did it using nano. I also ran this from shell 100 times and recorded results:</p><p>[code]for (( i=0; i<100; i++ )); do php rand.php >> rand.txt; echo $'\r' >> rand.txt & done[/code]</p><p>Results: <a href="http://pastebin.com/raw/akhAx2Lv" target="_blank">http://pastebin.com/raw/akhAx2Lv</a></p></blockquote><p></p>
[QUOTE="Ecko, post: 375427, member: 24874"] Your method is 33.33% chance for any. The way [USER=9520]@Wess[/USER] described would be how you get the proper odds: [php] <?php $rand = rand(1, 100); $amount = array("50", "100", "250"); if($rand <= '70') { echo "You win $amount[0]"; } elseif ($rand > '70' && $rand < '90') { echo "You win $amount[1]"; } else { echo "You win $amount[2]"; } [/php] Don't mind the sloppiness, I did it using nano. I also ran this from shell 100 times and recorded results: [code]for (( i=0; i<100; i++ )); do php rand.php >> rand.txt; echo $'\r' >> rand.txt & done[/code] Results: [URL]http://pastebin.com/raw/akhAx2Lv[/URL] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
Picking a reward amount based on odds
Top