Monkuar Posted January 24, 2012 Share Posted January 24, 2012 I need to use the rand function but how would I go about incorporating into let's say.. somone spends some (Forum gold) on my site, (you get these golds from posting) Somone buys a Scratch Ticket and it will give them 1-200 forum Gold (random chance) how would I go about doing that with the rand function? Also, could there be something I add like a % value that it will be less then 200 inside the 1-200 phase? Kinda confusing, but pretty much can I say 50% of users will get less then 50 Forum Gold from the 1-200FG Chance Ticket? Pretty much adding a % modifier with the rand function so people don't get essentially "Free" forum gold, that there is a 20% of actually getting 100-200 AMOUNT, and 80% of actually getting less then 100? Any idea? i know how to code it with mysql/php I just need somone to lift me up right now and get a little boost of code/help to get me started and a explanation Quote Link to comment https://forums.phpfreaks.com/topic/255652-scratch-tickets/ Share on other sites More sharing options...
MasterACE14 Posted January 24, 2012 Share Posted January 24, 2012 start with this... $gold = rand(1,200); // random amount of gold somewhere from 1 to 200 Quote Link to comment https://forums.phpfreaks.com/topic/255652-scratch-tickets/#findComment-1310539 Share on other sites More sharing options...
Monkuar Posted January 24, 2012 Author Share Posted January 24, 2012 start with this... $gold = rand(1,200); // random amount of gold somewhere from 1 to 200 Ok thanks, now can I add a & multiplier to that $gold variable let's say 20% out of 100% of getting 150 to 200 out of the 1-200? Quote Link to comment https://forums.phpfreaks.com/topic/255652-scratch-tickets/#findComment-1310543 Share on other sites More sharing options...
Pikachu2000 Posted January 24, 2012 Share Posted January 24, 2012 Something like this is what comes to mind. This would end up with roughly a 20% chance of having a chance of getting an amount from 100 to 200. There's probably a better way, but it's late, and I'm tired. Quote Link to comment https://forums.phpfreaks.com/topic/255652-scratch-tickets/#findComment-1310548 Share on other sites More sharing options...
Pikachu2000 Posted January 24, 2012 Share Posted January 24, 2012 So tired I forgot to paste in the code, apparently. But anyhow, I had a flaw in it. This would give about a 50/50 shot at the ensuing 50/50 shot of getting 100+ points. Overall should be about a 25% probability of getting 100+. $max = array_rand( array_flip(array(99,200)) ); $rand = mt_rand(1, $max); echo $rand; Quote Link to comment https://forums.phpfreaks.com/topic/255652-scratch-tickets/#findComment-1310549 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.