A-level Computing/AQA/Paper 1/Fundamentals of programming/Random number generation





An essential part of most games is the ability to use random numbers. These might be used to randomly place gold coins on a map, or to calculate whether you hit a target with a rifle at some distance.

The above code will give you a random number between 1 and 2,147,483,647. You might well require a number that is a little smaller. To get a random number between two set numbers, in this case 5 and 10 you can use the following: So how exactly can we use this? Take a look at the following game: Adjust the code above to tell the user how many guesses they took to find the random number. HINT: you'll need a variable