Now we're looking at the code.
This wasn't the exact file I had but maybe something has changed I don't know, it's close enough in the places that matter anyways.
Anyways for the crux of my argument, take lines 124 through 142 which consist of the bulk of the random number generator.
These are currently implemented as defines.
defines are a sort of macro they're going to be put into the final output as the code they represent.
Ask yourself what happens if you just have that section of code isolated as it's own separate core.
Then modify the code to call into that core rather than keep repeating that section over and over again?
Now we're on the same page. It would be a start. There are some other things I see a well, but I'll just keep that under my hat until I get a chance to make sure I'm right.