Skip to content

Course home

Random number generation in a programming language

Random number generation in a programming language

Easy
12345678
Question 7

A program simulates a lottery draw where a winning number is randomly chosen.

The program should generate a random number between 1 and 50 (including 1 and 50). This will represent the winning lottery ball number.

Write the VB.NET code that should be used on line 3 of the program below to:

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

You must use rand.Next(a, b) in your VB.NET code.

Note: rand.Next(a, b) generates a random integer starting at a up to, but not including, b.

1      Dim rand As New Random()
2      Dim winningBall As Integer
3
4      Console.WriteLine("Enter your lottery choice (1-50):")
5      Dim playerSelection As Integer = Console.ReadLine()
6      While playerSelection < 1 Or playerSelection > 50
7          Console.WriteLine("Invalid selection")
8          playerSelection = Console.ReadLine()
9      End While
10     Console.WriteLine("Selection accepted")
11     If winningBall = playerSelection Then
12         Console.WriteLine("You won the jackpot!")
13     End If
[2]
Markscheme

Random number generation in a programming language Questions

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

8 exam-style questions on AQA GCSE Computer Science Random number generation in a programming language. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank