benphp Posted February 8, 2010 Share Posted February 8, 2010 This may be tricky. Say I have an average - Average Income Level for Alaska = 33987. I want to create a page that will generate a random income for an Alaskan, based on this average. So the majority of incomes generated would be between 30000 and 35000, but occasionally, you'd get 11000 or even 800000. Any ideas? Thanks! Link to comment https://forums.phpfreaks.com/topic/191378-how-to-generate-statistical-model-using-an-average/ Share on other sites More sharing options...
aeroswat Posted February 8, 2010 Share Posted February 8, 2010 This may be tricky. Say I have an average - Average Income Level for Alaska = 33987. I want to create a page that will generate a random income for an Alaskan, based on this average. So the majority of incomes generated would be between 30000 and 35000, but occasionally, you'd get 11000 or even 800000. Any ideas? Thanks! Depends on many things such as how often do you want to escape that +/- boundary, how large you want the inside boundary, how large you want the outside boundary Link to comment https://forums.phpfreaks.com/topic/191378-how-to-generate-statistical-model-using-an-average/#findComment-1008950 Share on other sites More sharing options...
aeroswat Posted February 8, 2010 Share Posted February 8, 2010 In short to answer your question without you answering my questions this is what you would do $avgincome = whatever the avg income is $innerboundary = whatever you want (the boundary will be +/- this number) $outerboundary = whatever you want (the boundary will be +/- this number) for($i=0;$i<however many different incomes you want to generate;$i++) { if(rand(0,1 in however many times you want to go outside-1)){ (example: 1 in 8 times would be rand(0,7) echo rand((($avgincome - $innerboundary) < 0) ? '0' : ($avgincome - $outerboundary)), ($avgincome + $innerboundary)); } else{ echo rand((($avgincome - $outerboundary) < 0) ? '0' : ($avgincome - $outerboundary)), ($avgincome + $outerboundary)); } } Link to comment https://forums.phpfreaks.com/topic/191378-how-to-generate-statistical-model-using-an-average/#findComment-1008959 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.