Load module only in worker processes?

Please use this template for troubleshooting questions.

My issue:

We have a nginx module that uses a random generator (Mersenne twister from boost library) that is implemented as a static variable in a C++ function called init_rand(). It happens that all nginx worker processes produce exact same numbers sequences if the random generator is initialized in first nginx load process because init_rand() function is called when some global variable is initialized when the module is loaded via dlopen. All that seems a consequence of the fact fork() is used to create the worker processes and therefore the static variable in init_rand() are all in same state in worker processes.

How I encountered the problem:

Testing some client code using the module via http requests.

Solutions I’ve tried:

Use init process callback to flag in the code we are in master or worker process and abort if the former. Ideally it would be better if possible at all that module is only loaded in workers.

Version of NGINX or NGINX adjacent software (e.g. NGINX Gateway Fabric): 1.24.0

Deployment environment:

Minimal NGINX config to reproduce your issue (preferably running on https://tech-playground.com/playgrounds/nginx for ease of debugging, and if not as a code block): (Tip → Run nginx -T to print your entire NGINX config to your terminal.)

NGINX access/error log: (Tip → You can usually find the logs in the /var/log/nginx directory.)