Out of curiosity, how does one access said ID? I tried running OP's code with a bunch of random nodes, and this is what I got:
[[Particles2D:1201], [Node2D:1202], [AnimatedSprite:1206], [AnimationPlayer:1203], [AudioStreamPlayer:1204], [Bone2D:1205]]
[[Particles2D:1201], [AnimationPlayer:1203], [Node2D:1202], [Bone2D:1205], [AnimatedSprite:1206], [AudioStreamPlayer:1204]]
So apparently they are not sorted according to RID. The Node.get_index() has a different meaning - and might be useful in OP's case. I tried looking into the source but I can't seem to find any mention of "operator <" in either Node or Object classes.