Creative Thread Execution Options

Hello ladies and gents,

I would like to implement a solution in a Driver that executes a particular function ‘periodically’. The function serves a specific purpose and execution time is short, but I’d like to invoke it at ‘random’ intervals. I am also open to an Event based option, where a randomly generated timer interval sets an event that invokes this function (thread).

Is there anything I need to consider with such a design in the kernel? Are there any best practices I should be aware of as it pertains to random thread execution. Any particular combination of NT API’s I should use to implement this? Thank you for all input.

That’s not particularly normal.

You don’t need cryptographically secure numbers here, and It’s easy to implement a simple linear congruential random number generator in 3 or 4 lines of code. So, just create a timer, and assign a new interval each time it fires.

NTSYSAPI ULONG RtlRandomEx(
[in, out] PULONG Seed
);
Defined in ntifs.h. It is even documented. Also why not just have your own thread that is dedicated to executing your function and then waiting with a random delay on an event? If the event is signaled, the thread terminates. If the wait times out, it runs your function.