The program should simulate allocating a random loading bay by generating a random integer between 12 and 75 (including 12 and 75).
Figure 1
1 Random randGen = new Random();
2 int assignedBay;
3
4 Console.WriteLine("Enter your preferred bay (12-75):");
5 int preferredBay = Convert.ToInt32(Console.ReadLine());
6 while (preferredBay < 12 || preferredBay > 75)
7 {
8 Console.WriteLine("Invalid bay, choose between 12 and 75");
9 preferredBay = Convert.ToInt32(Console.ReadLine());
10 }
11 Console.WriteLine("Allocating random loading bay...");
12 if (assignedBay == preferredBay)
13 {
14 Console.WriteLine("Success! Your preferred bay was allocated!");
15 }
Write the C# code that should be used on line 3 in Figure 1 to:
You must use randGen.Next(a, b) in your C# code.
Note: randGen.Next(a, b) generates a random integer in the range a to b starting at a but finishing one before b.
Practise AQA GCSE Computer Science Random number generation in a programming language with exam-style questions for GCSE Computer Science. 8 questions, matched to the AQA GCSE Computer Science (8525) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.