Michdd Posted November 8, 2008 Share Posted November 8, 2008 Is it possible that I could create something where it would output 1 of a couple of options, and give it so there's a probability different for each of those results? Quote Link to comment https://forums.phpfreaks.com/topic/131964-solved-random-result-but-giving-possiblity/ Share on other sites More sharing options...
DeanWhitehouse Posted November 8, 2008 Share Posted November 8, 2008 You could maybe use shuffle with an array if that's what you mean? Edit: To be annoying: Anything is possible, so yes it is possible, but what you are most likely asking is can we show you how? Quote Link to comment https://forums.phpfreaks.com/topic/131964-solved-random-result-but-giving-possiblity/#findComment-685684 Share on other sites More sharing options...
Michdd Posted November 8, 2008 Author Share Posted November 8, 2008 You could maybe use shuffle with an array if that's what you mean? Edit: To be annoying: Anything is possible, so yes it is possible, but what you are most likely asking is can we show you how? Yea sorry, I know most things are possible, but I wasn't sure if this was possible, with shuffle you can set 1 thing to be output more commonly than another thing? If so, how? Quote Link to comment https://forums.phpfreaks.com/topic/131964-solved-random-result-but-giving-possiblity/#findComment-685690 Share on other sites More sharing options...
DeanWhitehouse Posted November 8, 2008 Share Posted November 8, 2008 I think you are stuck on the logic? Example <?php $arr = array( '1', '1', '2' ); echo shuffle($arr[0]);// it has a 2 in 3 chance of printing the number 1 ?> or <?php $num = rand(0,3);//make a random number between 1 & 100 $arr = array( '1', '2', '3' ); echo $arr[$num];// this will show each one with the same chance. ?> Quote Link to comment https://forums.phpfreaks.com/topic/131964-solved-random-result-but-giving-possiblity/#findComment-685693 Share on other sites More sharing options...
Michdd Posted November 8, 2008 Author Share Posted November 8, 2008 I think you are stuck on the logic? Example <?php $arr = array( '1', '1', '2' ); echo shuffle($arr[1]);// it has a 2 in 3 chance of printing the number 1 ?> Ah, I see, awesome, thanks I a lot. Quote Link to comment https://forums.phpfreaks.com/topic/131964-solved-random-result-but-giving-possiblity/#findComment-685696 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.