Suppose you have 100 questions, create a collection or array containing 100 boolean values, all set to false. Now generate a random number between 0 and 99. Suppose you got 37, check if the item at index 37 is true or false; if it's false display question 38 and set item 37 to true. If item 37 is true start iterating from 38 to 99 until you find one that's not used. When you find one, mark it as used and display the question number. Repeat until all elements are used. Suppose you iterate upwards hit 99 and still don't find an unused question then start from 36 and iterate downwards. You can also alternate the direction of iteration i.e. up then down then up etc.