wingman007

ExamMixTaskNumbers

Mar 27th, 2025 (edited)
15,048
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.73 KB | None | 0 0
  1. namespace RandNumbers
  2. {
  3.   internal class Program
  4.   {
  5.     static void Main(string[] args)
  6.     {
  7.       Random randGen = new Random();
  8.       int[] array2Mix = new int[26];
  9.       for (int i = 0; i < array2Mix.Length; i++)
  10.       {
  11.         array2Mix[i] = i;
  12.       }
  13.       int[] resultArray = new int[array2Mix.Length];
  14.       int randNumber = 0;
  15.       List<int> alreadyGenerated = new List<int>();
  16.       for (int i = 0; i < array2Mix.Length; i++)
  17.       {
  18.         do
  19.         {
  20.           randNumber = randGen.Next(0, array2Mix.Length);
  21.         } while ( alreadyGenerated.Contains(randNumber));
  22.         alreadyGenerated.Add(randNumber);
  23.         resultArray[i] = array2Mix[randNumber];
  24.         Console.WriteLine("{0,3:000}", array2Mix[randNumber]);
  25.       }
  26.  
  27.       // check if all numbers from 0 to 25 are there in the array
  28.       bool isFound = false;
  29.       int? foundAtPosition = null;
  30.       for (int i = 0; i < array2Mix.Length; i++)
  31.       {
  32.         isFound = false;
  33.         foundAtPosition = null;
  34.         for (int j = 0; j < resultArray.Length; j++)
  35.         {
  36.           if (array2Mix[i] == resultArray[j])
  37.           {
  38.             isFound = true;
  39.             foundAtPosition = j;
  40.             break;
  41.           }
  42.         }
  43.         if (foundAtPosition != null)
  44.         {
  45.           Console.WriteLine($"array2Mix[{i}] = {array2Mix[i]} found at position {foundAtPosition}");
  46.         }
  47.         else
  48.         {
  49.           Console.WriteLine($"array2Mix[{i}] = {array2Mix[i]} NOT FOUND");
  50.         }
  51.       }
  52.     }
  53.   }
  54. }
  55. /*
  56. Use with combination with Excel
  57. The tasks in the second column. The generated numbers in the first column and sort them by first column. The tasks will be mixed
  58. For faculty numbers in Excel use format 00#
  59. */
Tags: exam Task
Advertisement
Comments
  • User was banned
  • User was banned
Add Comment
Please, Sign In to add comment