wingman007 icon

ExamMixTaskNumbers

wingman007 | PRO | 03/27/25 07:58:49 AM UTC (Edited) | 0 ⭐ | 13197 👁️ | Never ⏰ | [exam, Task]
C# |

1.73 KB

|

None

|

0 👍

/

0 👎

namespace RandNumbers
{
  internal class Program
  {
    static void Main(string[] args)
    {
      Random randGen = new Random();
      int[] array2Mix = new int[26];
      for (int i = 0; i < array2Mix.Length; i++)
      {
        array2Mix[i] = i;
      }
      int[] resultArray = new int[array2Mix.Length];
      int randNumber = 0;
      List<int> alreadyGenerated = new List<int>();
      for (int i = 0; i < array2Mix.Length; i++)
      {
        do
        {
          randNumber = randGen.Next(0, array2Mix.Length);
        } while ( alreadyGenerated.Contains(randNumber));
        alreadyGenerated.Add(randNumber);
        resultArray[i] = array2Mix[randNumber];
        Console.WriteLine("{0,3:000}", array2Mix[randNumber]);
      }
 
      // check if all numbers from 0 to 25 are there in the array
      bool isFound = false;
      int? foundAtPosition = null;
      for (int i = 0; i < array2Mix.Length; i++)
      {
        isFound = false;
        foundAtPosition = null;
        for (int j = 0; j < resultArray.Length; j++)
        {
          if (array2Mix[i] == resultArray[j])
          {
            isFound = true;
            foundAtPosition = j;
            break;
          }
        }
        if (foundAtPosition != null)
        {
          Console.WriteLine($"array2Mix[{i}] = {array2Mix[i]} found at position {foundAtPosition}");
        }
        else 
        {
          Console.WriteLine($"array2Mix[{i}] = {array2Mix[i]} NOT FOUND");
        }
      }
    }
  }
}
/*
Use with combination with Excel
The tasks in the second column. The generated numbers in the first column and sort them by first column. The tasks will be mixed
For faculty numbers in Excel use format 00#
*/

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎