+ Reply to Thread
Results 1 to 2 of 2

Thread: Run my code only 1/3 the time

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    14

    Run my code only 1/3 the time

    I have a code that checks for something and i only need it to work like 1/3 a time
    So i used :
    Code:
    if (mt_rand(1, 3) == 2)
    {
        MyFunc();
    }
    So any idea how could i do that ?

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    24
    Well since you are using random then i can`t guarantee it will be called 30% of the time , but
    you can use a module that will effectively give you 1/3 of the time and here you are :
    Code:
    $max = 27;
    
    for($i = 1; $i < $max; $i++){
        if($i % 3 == 0){
            MyFunc();
        }
    }

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts