-1

How can I generate Random strings which are saved into a array? In the language c#

So I would like to generate Random Names (strings) which are saved into an array

I only know, that I can generate Random Numbers with the Random Method ( Iam learning programming now and I dont have much experience)

Thanks for your help.

  • Please, start from the *definitions*, e.g. what *name* is. Are `Tim`, `tiM`, `123Tim`, `Tim_123`, `123`, `123+456` valid names? If not why? – Dmitry Bychenko Apr 18 '20 at 07:09
  • The duplicate (https://stackoverflow.com/questions/1344221/how-can-i-generate-random-alphanumeric-strings) shows how to generate random strings, hopefully you should already know how to set an element of an array to value you created based on info from duplicate. If that is not what you are asking - [edit] question to clarify and show what you tried – Alexei Levenkov Apr 18 '20 at 07:47

1 Answers1

-1
  int length = 7;

      // creating a StringBuilder object()
      StringBuilder str_build = new StringBuilder();  
      Random random = new Random();  

      char letter;  

      for (int i = 0; i < length; i++)
      {
        double flt = random.NextDouble();
        int shift = Convert.ToInt32(Math.Floor(25 * flt));
        letter = Convert.ToChar(shift + 65);
        str_build.Append(letter);  
      }  

With this code you can achieve that. Basically you create random number and convert it into character