Implementation change to .NET's Random()

前端 未结 5 842
清歌不尽
清歌不尽 2021-01-11 09:25

I am migrating a method that is used for decoding from .NET Framework 1.1 to .NET Framework 4. I noticed that implementation of Random changed. So given the same seed, Rando

5条回答
  •  隐瞒了意图╮
    2021-01-11 10:17

    Alternatively, might I suggest using System.Security.Cryptography.RandomNumberGenerator class to generate cryptographically strong random byte arrays?

    RandomNumberGenerator rng = RandomNumberGenerator.Create();
    byte[] bytes = new byte[128];
    rng.GetBytes(bytes);
    

    I will join the rest of the comments, and mention that relying on an undocumented implementation is bad. More so, if you're actually relying on a predictable "randomness" - if you're using this for anything that should be "secure" - it is totally wrong.

提交回复
热议问题