1Easy
0/2

A program simulates a wind-tunnel environment where a random wind bearing in degrees (from 0 to 359, inclusive) is generated.

1      Random generator = new Random();
2      int windBearing;
3
4      Console.WriteLine("Enter your estimated bearing (0-359):");
5      int userBearing = Convert.ToInt32(Console.ReadLine());
6      while (userBearing < 0 || userBearing > 359)
7      {
8          Console.WriteLine("Invalid bearing. Enter a value from 0 to 359:");
9          userBearing = Convert.ToInt32(Console.ReadLine());
10     }
11     Console.WriteLine("Simulating wind bearing...");
12     if (windBearing == userBearing)
13     {
14         Console.WriteLine("Perfect estimate!");
15     }

Write the C# code that should be used on line 3 to:

  • generate a random integer between 0 and 359 inclusive
  • assign this number to the appropriate variable from the program.

You must use generator.Next(a, b) in your C# code.

Note: generator.Next(a, b) generates a random integer in the range a to b starting at a but finishing one before b.

[2]

Random number generation in a programming language Questions

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.

Next

Random number generation in a programming language Questions

  1. GCSE
  2. /Computer Science
  3. /Random number generation in a programming language