C code to generate random numbers

  • 2021-01-03 21:01:30
  • OfStack


///  Constructed random number   seeds 
static int GetRandomSeed()
{
      byte[] bytes = new byte[4];
      System.Security.Cryptography.RNGCryptoServiceProvider rng = new System.Security.Cryptography.RNGCryptoServiceProvider();
      rng.GetBytes(bytes);
      return BitConverter.ToInt32(bytes, 0);
} 
 
///  Generate random   The number 
static int rnd() 
{
      
      Random ran = new Random(GetRandomSeed());     
      int cnt = ran.Next(0,59);
      return cnt;
 }

That's the end of this article, I hope you enjoy it and it will be helpful for you to learn C#.


Related articles: