Random delay

hi Ruri
could you please tell me if its possible to do random delay, the delay functiom we all know is that yo give it how much seconds should before start the next thing, i just want to know if its possible to make it random like each time will be deferent sometimes will be 1 min sometime will like 1 hr.

will be great to set min and max like make it chose between 1 min and 1 hr.

Hello @BEAST89

(First way)

Blocks
You have two easy way to do it the first way is that you use the random block so you could do a random time between two numbers that you have chosen :
Capture
You have your minimum and you have your maximum you recover the output variable and you pass it in the block delay.
What is good with this block is that it is inclusive which means that in this case the 360000 will not be excluded but included.

BLOCK:RandomInteger
  minimum = 60000
  maximum = 3600000
  => VAR @randomIntegerOutput
ENDBLOCK

BLOCK:Delay
  milliseconds = @randomIntegerOutput
ENDBLOCK

(Second way) :
C#

Here you generate a number between a minimum and a maximum then you give it to the delay block but you have to convert it to a string and unlike Ruri’s block the Random. Next excludes the max so you have to add 1 to overcome this problem


 //Generation of a new random
 Random SecondWay = new Random();

//360000 excluded you must add 1
 string delay = SecondWay.Next(60000,360001).ToString();

BLOCK:Delay
  milliseconds = @delay
ENDBLOCK*/

WannaCry

1 Like

thank you so much im going test both ways.
thank you i really appreciate it.

@WannaCry

can random function work with list i mean pick random line from list.
for example make constant block contains links for example:
link1. com
link2. com
link3 .com

is there anyway to pick one line randomly.?

Of course you can @BEAST89

Code :

Random rand = new Random();
int yes = rand.Next(1,6);

BLOCK:ConstantList
  value = ["link1.com", "link2.com", "link3.com", "link4.com", "link5.com"]
  => VAR @MyList
ENDBLOCK

BLOCK:ConstantString
  value = $"<MyList[yes]>"
  => VAR @MyRandomLine
ENDBLOCK

With the funtion block now :

BLOCK:RandomInteger
  maximum = 5
  => VAR @yes
ENDBLOCK

BLOCK:ConstantList
  value = ["link1.com", "link2.com", "link3.com", "link4.com", "link5.com"]
  => VAR @MyList
ENDBLOCK

BLOCK:ConstantString
  value = $"<MyList[yes]>"
  => VAR @MyRandomLine
ENDBLOCK

2 Likes

@WannaCry

both codes worked perfectly as i wanted but sometimes i get this error message

Screenshot 2022-10-04 210118

That means you are calling an index that is not available in the collection @BEAST89
This usually happens when you manipulate data in a list :
Capture
To illustrate this example look here :

List<string> caf = new List<string>()
            {
               "Openbullet 1","Openbullet 2"
            };

            for(int i = 0; i < caf.Count + 1; i++)
            {
                Console.WriteLine(caf[i]);
            }
//This will not work because i have 1 to count and i will got the exception because i try to
//get index nonexistent

This now will work because i dont have problem with my list.Count

List<string> caf = new List<string>()
            {
               "Openbullet 1","Openbullet 2"
            };

            for(int i = 0; i < caf.Count; i++)
            {
                Console.WriteLine(caf[i]);
            }

Hope you understand

1 Like

@WannaCry
yes i do understand now
thank you so much