There is a cron script on which the function is executed

Generate(17, "test",3,1 , int(rand(3)+1));

The final argument is a random number, which is already passed to the function itself. How to write the argument so that the number from one to three is transmitted alternately, each time this script is executed on the crown?

  • 2
    save the last number somewhere (config, system variables) and the problem will go away by itself. - KoVadim

1 answer 1

You must save the counter somewhere, and pass the remainder by 3 to the function:

 my $counter = read_from_config() Generate(17, "test",3,1 , $counter%3 +1); save_to_config( ++$counter ); 

because the remainder of division by 3 can be: 0, 1, 2, then we must add 1 here to get your required: 1, 2, 3

  • Why is it so difficult if you can just save the last number, as suggested by KoVadim, without divisions / additions? - MAN69
  • @ MAN69: Need to pass numbers от 1 до 3 . Do you suggest you do logic? - Eugen Konkov