mercredi 5 mai 2021

RandomNumberGenerator GetInt32 not defined

I have to change the random number generation in multiple places in the sourcecode for the company I am working at, to use the RandomNumberGenerator class instead of the Random class for security reasons.

After looking at the ms docs I figured I have to use the Create() method to make an instance of RandomNumberGenerator. Everything is fine, I could use the GetBytes() function without a problem, but I can't seem to be able use the GetInt32() which is used for generating ints. I've first tried calling it from the instance, then I saw in the documentation that it is a static function, so i've tried calling it like so RandomNumberGenerator.GetInt32(256) but it doesn't contain a definition, the only methods that intellisense suggests me are Create, Equals and ReferenceEquals and I am quite confused as to why?

I have the namespace System.Security.Cryptography included.

I've tried googling around to see implementations, or if someone else had the same question but I couldn't find anything relatable.

EDIT: We are using .net framework 4.8 so I've been looking at the wrong documentation and this should be the correct one. This one doesn't contain a definition for GetInt32 or anything like that so now I am not sure what should I use to generate random integers safely.




Aucun commentaire:

Enregistrer un commentaire