or on another code i get R=X which was surprising...
In a ECDSA process the R value is always equals to the X value of the result of multiply your random nonce K by the generator point.
This is
Publickey = k*G
R = Publickey.X
You can check the full process in:
https://cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-messagesIn your examples none of the K values generate those X or R values that your are showing, that's means that you are doing something wrong or your scripts are doing something weird, so any extra calculations with your current ""K"" value will be wrong, maybe you are skipping some steps or maybe you are confused about what you are doing.
But without any extra information we can't help.