Jump to content

Random base on a percentage


rsalumpit

Recommended Posts

            RAIN    SNOW  FOG  WIND

SPRING    30%    0%      30%  30%

SUMMER  15%    0%      30%  30%

FALL      10%    0%      30%  30%

WINTER  10%    30%    40% 30%

 

how can i base in the percentage of all the given data for example:

 

spring  has to be 30%(rain,snow,fog,wind) probability

and make a random function with exact probobility?

thnx guys

 

Link to comment
https://forums.phpfreaks.com/topic/168299-random-base-on-a-percentage/
Share on other sites

<?php

$a = rand(1,100);

?>

 

This will get a random number between 1 and 100 (to check the first condition)

if the number is between 1 and 30, it will rain. 31-60 it will be foggy. 61-90 it will be windy.  I guess 91-100 would be a clear sunny day ?  that isn't really stipulated in your condition

 

you can use the same basic calculation for the others

<?php

$a = rand(1,100);

?>

 

This will get a random number between 1 and 100 (to check the first condition)

if the number is between 1 and 30, it will rain. 31-60 it will be foggy. 61-90 it will be windy.  I guess 91-100 would be a clear sunny day ?  that isn't really stipulated in your condition

 

you can use the same basic calculation for the others

i think this is it man thanks ill try this..thnx to all

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.