One potential way I can think off the top of my head:
Each frame, compare the current frame number to the previous (and then store the current frame number as the previous). If the current frame isn't one greater than the previous, then you have loaded a savestate.
There may be a better way, but there's currently no built in callbacks for savestate loading if I recall, and I don't see any obvious flaws with this method.
Edit: My recollection was wrong, as Amaraticando points out,
event.onloadstate exists and should be preferred as a more robust solution than the hacky solution of comparing to the previous frame. My apologies for being too lazy to even check the documentation (I am a bit averse to BizHawk's Lua docs, since I find them to be poorly formatted and difficult to use, but that is no excuse.) As for flaws with the previous method, I'm writing a reply currently, but I concede my method is not perfect for all cases.
Code example with a callback:
Language: lua
event.onloadstate(randomize_rng)
<h2>My original, less robust method</h2>
Code-wise, it would be something like:
Language: lua
local prev_frame = emu.framecount() - 1
while true do
local curr_frame = emu.framecount()
if curr_frame ~= prev_frame + 1 then
randomize_rng()
end
prev_frame = curr_frame
emu.frameadvance()
end