SRL Archive - OSR Help

Randomize multiple procedure


Main

2010-11-09 23:58:50

I am not sure if something like this exists so here we go.
Lets say I have x number of procedures and I would like to lunch them all but in random order. Is there a function or a easy way (without case randoming infinite amount of permutation)?

i luffs yeww

2010-11-10 00:01:36

I know there is a WaitFunc method, where you'd do WaitFunc(@Something, 100);, so I'm sure I'm sure there's a way. You could look at how MSI does something kinda on topic with full scripts being able to be called in DeclarePlayers I think.

Main

2010-11-10 00:05:33

I am not sure on what you mean:(
This is my problem:
For example lets say I have like 300 types of antiban (not my case) and I would like to use them all in random order.
All I can think of is maybe put them in branches of case random, but I think a more efficient way would exist.
Something like:
Randomize:
1:P1;
2:P2;
3:P3;
4:P4;
…etc

If something like that doesn't exist, maybe we can create something like that? It does not have to be like that above but it would be nice:p too bad there isn't array of procedures (or is there?).

ZephyrsFury

2010-11-10 20:33:32

The is an array of procedure or an array of function. But this requires all your procedures/functions to have the same parameters.

You could do something like this:


var ProcArray: array of procedure;

ProcArray := [@P1, @p2, @p3, @p4];

//to call a random proc

ProcArray[Random(Length(ProcArray))]();

That should work. You still need to define each procedure nomrally, then put each handle into the ProcArray.

Bad Boy JH

2010-11-10 22:11:07

If you want all procedures to be done, try this…
Procedure ExecuteProcedures;
var
IntArr: TIntegerArray;
Number, Count, I: Integer;
begin
SetArrayLength(IntArr, NumberOfProcedures);
//from here...
while InIntArray(NumberOfProcedures, 0) do
begin
Number := Random(NumberOfProcedures);
if InIntArray(NumberOfProcedures, Number) then
IntArr[Count] := Number;
Inc(Count);
end;
//...to here
//creates an array of unique integers

for I := 0 to High(IntArr) do
//Optionally instead of High(IntArr) use the amount of procedures you want to do, minus 1
Case IntArr[I] of
0 : Proc1;
1 : Proc2;
2 : Proc3;
3 : Proc4;
{and so on}
end;
end;

That should also help me do something, thanks for making me get that idea…