Righteousness doesn't just happen, it is built step by step on a daily basis. It is not an “unchangeable” part of out character – something, like our body type or sex, that has been given us from the start. When we need righteousness, if we haven't been working to build it, it will not be there
The act of righteousness is staying on a prescribed path. Righteousness is like a pathway across a field, we know what is “path” and what is “field”. To walk off the path is to walk into what is not known as righteousness. At the best it is undefined, at the wort it is wickedness. Someone has established what is right and what is wrong. God has told us both: what is right and what is wrong. Other sources can tell us this too. However, other sources may only tell us what, according to them, is right; still others may tell us only what is wrong. If the others are not God what they define for us as right may be, in fact, wrong.
Righteousness and wickedness start from within. For the righteous what is within will preserve him when trouble comes, when the outward, uncontrollable, hurtful situation occurs. However, what was internal to the wicked will have no worth for his deliverance.
The righteous would have been doing good acts and gaining a reputation for it. Perhaps that is what helps save them. Perhaps right internal responses results in the right outward responses in the time of trouble.