Quote:
like if have total number of 4 question only 3 should be asked from the quiz taker
Your random is to draw 3 questions out of 4 in random order, with no repeat, the trick is that this is not random, it is
shuffle.
Think of a deck of cards. First you shuffle the deck of card, then you draw the first n cards. It comes in random sequence and with no repeat.
Shuffle a given array using Fisher–Yates shuffle Algorithm - GeeksforGeeks[
^]
Fisher–Yates shuffle - Wikipedia[
^]
Since it is a web app, this imply a few things:
- you need to keep track of a shuffle result per user taking the quizz at same time.
- need to keep track user score as user answer questions, and number of questions remaining.
- it is a bad idea to embed the answer in the web page, a curious user can just read the answers in the source code of the page.