Random Numbers - from a set list not repeating within that list.
Posted on 2004-09-27
I am creating an application which is basically a quiz. The idea is the user gets asked a country and they have to type in the appropriate capital of that quiz e.g. USA - Washington DC, France - Paris , etc...
I have created a text file in the root of the project folder called quiz.txt and the layout is as follows:
The pipe sign is my delimeter.
I pull in the values from the txt file and store them in to arrays Capital and Country respectively. I then generate a random number, using a min value of 1 and a max value of the number of countries in the array.
This works successfully however it is still possible for it to chuck up and country at any time e.g. UK 3 times in a row. I want to know how to not generate a number that has already been generated.