473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

randomising for a quiz

Dear All

I am making a quiz with a four-option-multiple-choice scenario.

When you enter the quiz, you provide one answer and three wrong answers.

Then the contestant opens the quiz and I trying to present them the four
answers on the page in a randomized way (i.e. you have no idea which one
comes first).

I know the rnd command, but how do you do rnd without replacement?

TIA

- Nicolaas

Nov 13 '05 #1
10 1477
This is math not a computer group.
"WindAndWaves" <ac****@ngaru.com> wrote in message
news:TH********************@news.xtra.co.nz...
Dear All

I am making a quiz with a four-option-multiple-choice scenario.

When you enter the quiz, you provide one answer and three wrong answers.

Then the contestant opens the quiz and I trying to present them the four
answers on the page in a randomized way (i.e. you have no idea which one
comes first).

I know the rnd command, but how do you do rnd without replacement?

TIA

- Nicolaas


Nov 13 '05 #2
On Fri, 27 Aug 2004 15:14:52 +1200, "WindAndWaves" <ac****@ngaru.com>
wrote:
Dear All

I am making a quiz with a four-option-multiple-choice scenario.

When you enter the quiz, you provide one answer and three wrong answers.

Then the contestant opens the quiz and I trying to present them the four
answers on the page in a randomized way (i.e. you have no idea which one
comes first).

I know the rnd command, but how do you do rnd without replacement?

TIA

- Nicolaas


Set up an array of 4 elements.
Randomly choose one.
Remove it from the list.
Randomly choose one of the 3.
And so on.
Nov 13 '05 #3
Dear Michael

I had a go at this and this is what I came up with (slightly different):

Private Sub Form_Current()
'randomises the anwsers
Const ProEro = 12: 'on error GoTo ERR
'---
Dim Ctl As Control
Dim C(3) As Byte
Dim I As Integer
Dim J As Integer
'---assign numbers
For I = 0 To 3
TryAgain:
C(I) = Int(Rnd * 5)
If C(I) = 0 Or C(I) = 5 Then GoTo TryAgain
If I = 0 Then GoTo looper
'--- check if it exists already and try again if this is so
For J = (I - 1) To 0 Step -1
If C(I) = C(J) Then GoTo TryAgain
Next J
looper:
Next I
'---place data
For I = 0 To 3
Set Ctl = Me.Controls("O" & C(I))
Ctl.ControlSource = "=[QA" & I & "]"
Ctl.Tag = I
'---reset tickbox
Me.Controls("C" & I + 1) = False
Next I
xit:
Exit Sub
ERR:
Call FerrorLog(ERR.Number, 0, ProEro + Modero): Resume Next
End Sub
"Michael Gray" <fl****@newsguy.spam.com> wrote in message
news:dh********************************@4ax.com...
On Fri, 27 Aug 2004 15:14:52 +1200, "WindAndWaves" <ac****@ngaru.com>
wrote:
Dear All

I am making a quiz with a four-option-multiple-choice scenario.

When you enter the quiz, you provide one answer and three wrong answers.

Then the contestant opens the quiz and I trying to present them the four
answers on the page in a randomized way (i.e. you have no idea which one
comes first).

I know the rnd command, but how do you do rnd without replacement?

TIA

- Nicolaas


Set up an array of 4 elements.
Randomly choose one.
Remove it from the list.
Randomly choose one of the 3.
And so on.

Nov 13 '05 #4
On Sat, 28 Aug 2004 00:21:41 +1200, "WindAndWaves" <ac****@ngaru.com>
wrote:
Dear Michael

I had a go at this and this is what I came up with (slightly different):

:

If all you are trying to achieve is to get it to work, by far and away
the most efficient method (but no the most elegant perhaps), is to
pre-populate an array with the 24 possible permutations (of the four
questions), and choose one randomly from this list.
This is much more efficient than any other way.

So you would do something like this the first time the program runs:

Dim Permutation(24) As String
Permutation(0) = "1234"
Permutation(1) = "1243"
Permutation(2) = "1324"
Permutation(3) = "1342"
Permutation(4) = "1432"
Permutation(5) = "1423"
Permutation(6) = "2134"
Permutation(7) = "2143"
Permutation(8) = "2314"
Permutation(9) = "2341"
Permutation(10) = "2431"
Permutation(11) = "2413"
Permutation(12) = "3124"
Permutation(13) = "3142"
Permutation(14) = "3214"
Permutation(15) = "3241"
Permutation(16) = "3412"
Permutation(17) = "3421"
Permutation(18) = "4123"
Permutation(19) = "4132"
Permutation(20) = "4213"
Permutation(21) = "4231"
Permutation(22) = "4312"
Permutation(23) = "4321"

(I have used strings here for ease of demonstration only, and assume
an array base of zero [Option Base 0])

Then your subroutine would select one of these 24 elements at random,
and apply the order chosen.
I will leave it to you work out the mechanics...
Nov 13 '05 #5
That is a nice solution Michael, thank you for that idea.
"Michael Gray" <fl****@newsguy.spam.com> wrote in message
news:d4********************************@4ax.com...
On Sat, 28 Aug 2004 00:21:41 +1200, "WindAndWaves" <ac****@ngaru.com>
wrote:
Dear Michael

I had a go at this and this is what I came up with (slightly different):

:

If all you are trying to achieve is to get it to work, by far and away
the most efficient method (but no the most elegant perhaps), is to
pre-populate an array with the 24 possible permutations (of the four
questions), and choose one randomly from this list.
This is much more efficient than any other way.

So you would do something like this the first time the program runs:

Dim Permutation(24) As String
Permutation(0) = "1234"
Permutation(1) = "1243"
Permutation(2) = "1324"
Permutation(3) = "1342"
Permutation(4) = "1432"
Permutation(5) = "1423"
Permutation(6) = "2134"
Permutation(7) = "2143"
Permutation(8) = "2314"
Permutation(9) = "2341"
Permutation(10) = "2431"
Permutation(11) = "2413"
Permutation(12) = "3124"
Permutation(13) = "3142"
Permutation(14) = "3214"
Permutation(15) = "3241"
Permutation(16) = "3412"
Permutation(17) = "3421"
Permutation(18) = "4123"
Permutation(19) = "4132"
Permutation(20) = "4213"
Permutation(21) = "4231"
Permutation(22) = "4312"
Permutation(23) = "4321"

(I have used strings here for ease of demonstration only, and assume
an array base of zero [Option Base 0])

Then your subroutine would select one of these 24 elements at random,
and apply the order chosen.
I will leave it to you work out the mechanics...

Nov 13 '05 #6
On Sun, 29 Aug 2004 08:46:02 +1200, "WindAndWaves" <ac****@ngaru.com>
wrote:
That is a nice solution Michael, thank you for that idea.


Actually it's not my idea.
It dates from ancient times.
Logarithm tables are a good example, as are "Ready Reckoners" which
were essential in the days of Pounds, Shillings & Pence.
Often pre-populated tables are the most effective way to go with a lot
of problems, although it's surprising how many programmers shy away
from them, or don't even think of them.
They are particularly handy in programs that perform intensive
trigonometry. (Even if a F.P. processor is available)
A table of sin(x) covering an 8th of a circle to the required
precision is all that one needs. The rest of the circle can be
synthesised without having to call transcendental functions
repeatedly.
It's used a lot by people who program microprocessors in machine code,
who *do* tend to think this way.

Michael G.
Nov 13 '05 #7
Michael Gray <fl****@newsguy.spam.com> wrote in message news:<d4********************************@4ax.com>. ..
On Sat, 28 Aug 2004 00:21:41 +1200, "WindAndWaves" <ac****@ngaru.com>
wrote:
Dear Michael

I had a go at this and this is what I came up with (slightly different):

:

If all you are trying to achieve is to get it to work, by far and away
the most efficient method (but no the most elegant perhaps), is to
pre-populate an array with the 24 possible permutations (of the four
questions), and choose one randomly from this list.
This is much more efficient than any other way.

So you would do something like this the first time the program runs:

Dim Permutation(24) As String
Permutation(0) = "1234"
Permutation(1) = "1243"
Permutation(2) = "1324"
Permutation(3) = "1342"
Permutation(4) = "1432"
Permutation(5) = "1423"
Permutation(6) = "2134"
Permutation(7) = "2143"
Permutation(8) = "2314"
Permutation(9) = "2341"
Permutation(10) = "2431"
Permutation(11) = "2413"
Permutation(12) = "3124"
Permutation(13) = "3142"
Permutation(14) = "3214"
Permutation(15) = "3241"
Permutation(16) = "3412"
Permutation(17) = "3421"
Permutation(18) = "4123"
Permutation(19) = "4132"
Permutation(20) = "4213"
Permutation(21) = "4231"
Permutation(22) = "4312"
Permutation(23) = "4321"

(I have used strings here for ease of demonstration only, and assume
an array base of zero [Option Base 0])

Then your subroutine would select one of these 24 elements at random,
and apply the order chosen.
I will leave it to you work out the mechanics...


or.. more simply and elegantly.. pick a random number from 1 to 24..

then u can sieve through the # to find out which permutation it is..

if it's in the first 6.. 1 is first
second 6 2 is first
etc.

within that group of six..
if it's in the first 2.. etc.

in the 2.. the order of the two will determine the order of the last two...
it's very simple..
Nov 13 '05 #8
On 15 Sep 2004 19:21:56 -0700, dw*****@yahoo.com (David Bandel) wrote:
Michael Gray <fl****@newsguy.spam.com> wrote in message news:<d4********************************@4ax.com>. ..
On Sat, 28 Aug 2004 00:21:41 +1200, "WindAndWaves" <ac****@ngaru.com>
wrote:
>Dear Michael
>
>I had a go at this and this is what I came up with (slightly different):
>

:

If all you are trying to achieve is to get it to work, by far and away
the most efficient method (but no the most elegant perhaps), is to
pre-populate an array with the 24 possible permutations (of the four
questions), and choose one randomly from this list.
This is much more efficient than any other way.

So you would do something like this the first time the program runs:

Dim Permutation(24) As String
Permutation(0) = "1234"
Permutation(1) = "1243"
Permutation(2) = "1324"
Permutation(3) = "1342"
Permutation(4) = "1432"
Permutation(5) = "1423"
Permutation(6) = "2134"
Permutation(7) = "2143"
Permutation(8) = "2314"
Permutation(9) = "2341"
Permutation(10) = "2431"
Permutation(11) = "2413"
Permutation(12) = "3124"
Permutation(13) = "3142"
Permutation(14) = "3214"
Permutation(15) = "3241"
Permutation(16) = "3412"
Permutation(17) = "3421"
Permutation(18) = "4123"
Permutation(19) = "4132"
Permutation(20) = "4213"
Permutation(21) = "4231"
Permutation(22) = "4312"
Permutation(23) = "4321"

(I have used strings here for ease of demonstration only, and assume
an array base of zero [Option Base 0])

Then your subroutine would select one of these 24 elements at random,
and apply the order chosen.
I will leave it to you work out the mechanics...


or.. more simply and elegantly.. pick a random number from 1 to 24..

then u can sieve through the # to find out which permutation it is..

if it's in the first 6.. 1 is first
second 6 2 is first
etc.

within that group of six..
if it's in the first 2.. etc.

in the 2.. the order of the two will determine the order of the last two...
it's very simple..


I agree.

But for time critical routines, there's no substitute for a
pre-populated table.
I don't implement it as above, of course, but as an array of arrays.
One random look-up gives you the order without having to go through
seiving ranges.
They are "Pre-seived" as it were.

But you are right: your way is more elegant,
but I dispute that it is "simpler" to actually implement.
Nov 13 '05 #9
Here's what i came up with:

I assume the table with the questions has the following format:

Id
Question
RightAnswer
WrongAnswer1
WrongAnswer2
WrongAnswer3

Now the following query will give you the answers to question 1 in
random order:

SELECT Answer, Correct
FROM
(SELECT RND() AS Position, RightAnswer AS Answer, True AS Correct FROM
Questions WHERE Id = 1
UNION ALL
SELECT RND() AS Position, WrongAnswer1, False AS Correct FROM
Questions WHERE Id = 1
UNION ALL
SELECT RND() AS Position, WrongAnswer2, False AS Correct FROM
Questions WHERE Id = 1
UNION ALL SELECT RND() AS Position, WrongAnswer3, False AS Correct
FROM Questions WHERE Id = 1)
ORDER BY Position;

I hardcoded question 1 in there to keep it simple, when you open this
in VBA you replace that with the Id of the question you want to ask.
It almost as lengthy as the other alternative, it just looks more
'pure' to me.

Regards,

GJ
Michael Gray <fl****@newsguy.spam.com> wrote in message news:<k8********************************@4ax.com>. ..
On 15 Sep 2004 19:21:56 -0700, dw*****@yahoo.com (David Bandel) wrote:
Michael Gray <fl****@newsguy.spam.com> wrote in message news:<d4********************************@4ax.com>. ..
On Sat, 28 Aug 2004 00:21:41 +1200, "WindAndWaves" <ac****@ngaru.com>
wrote:

>Dear Michael
>
>I had a go at this and this is what I came up with (slightly different):
>
:

If all you are trying to achieve is to get it to work, by far and away
the most efficient method (but no the most elegant perhaps), is to
pre-populate an array with the 24 possible permutations (of the four
questions), and choose one randomly from this list.
This is much more efficient than any other way.

So you would do something like this the first time the program runs:

Dim Permutation(24) As String
Permutation(0) = "1234"
Permutation(1) = "1243"
Permutation(2) = "1324"
Permutation(3) = "1342"
Permutation(4) = "1432"
Permutation(5) = "1423"
Permutation(6) = "2134"
Permutation(7) = "2143"
Permutation(8) = "2314"
Permutation(9) = "2341"
Permutation(10) = "2431"
Permutation(11) = "2413"
Permutation(12) = "3124"
Permutation(13) = "3142"
Permutation(14) = "3214"
Permutation(15) = "3241"
Permutation(16) = "3412"
Permutation(17) = "3421"
Permutation(18) = "4123"
Permutation(19) = "4132"
Permutation(20) = "4213"
Permutation(21) = "4231"
Permutation(22) = "4312"
Permutation(23) = "4321"

(I have used strings here for ease of demonstration only, and assume
an array base of zero [Option Base 0])

Then your subroutine would select one of these 24 elements at random,
and apply the order chosen.
I will leave it to you work out the mechanics...


or.. more simply and elegantly.. pick a random number from 1 to 24..

then u can sieve through the # to find out which permutation it is..

if it's in the first 6.. 1 is first
second 6 2 is first
etc.

within that group of six..
if it's in the first 2.. etc.

in the 2.. the order of the two will determine the order of the last two...
it's very simple..


I agree.

But for time critical routines, there's no substitute for a
pre-populated table.
I don't implement it as above, of course, but as an array of arrays.
One random look-up gives you the order without having to go through
seiving ranges.
They are "Pre-seived" as it were.

But you are right: your way is more elegant,
but I dispute that it is "simpler" to actually implement.

Nov 13 '05 #10
On 16 Sep 2004 11:47:59 -0700, gj******@hotmail.com (G.J. v.d. Kamp)
wrote:
Here's what i came up with:

I assume the table with the questions has the following format:

Id
Question
RightAnswer
WrongAnswer1
WrongAnswer2
WrongAnswer3

Now the following query will give you the answers to question 1 in
random order:

SELECT Answer, Correct
FROM
(SELECT RND() AS Position, RightAnswer AS Answer, True AS Correct FROM
Questions WHERE Id = 1
UNION ALL
SELECT RND() AS Position, WrongAnswer1, False AS Correct FROM
Questions WHERE Id = 1
UNION ALL
SELECT RND() AS Position, WrongAnswer2, False AS Correct FROM
Questions WHERE Id = 1
UNION ALL SELECT RND() AS Position, WrongAnswer3, False AS Correct
FROM Questions WHERE Id = 1)
ORDER BY Position;

I hardcoded question 1 in there to keep it simple, when you open this
in VBA you replace that with the Id of the question you want to ask.
It almost as lengthy as the other alternative, it just looks more
'pure' to me.

Regards,

GJ


Once again, an interesting approach.
But if it's elegance and generality that you are looking for, you
can't beat recursion!

Here's a recursive class (in VB6) that can permute an arbitrarily
sized collection of arbitrary objects.
You can't get more general than that!
It's not all that long, considering what it does.

(If you want to translate this into VB.net, be careful about the
different way collections are based)

'Class: Permutations
'(C) Copyright 2001, Michael Gray
' Generate permutations of the CollectionsToPermute in the
CollectionsToPermute collection.
' Return the result through a collection of collections that each hold
a unique permutation.
Property Get GeneratePermutations(ByVal CollectionsToPermute As
Collection) As Collection
Dim num_CollectionsToPermute As Integer
Dim I As Integer
Dim J As Integer
Dim K As Integer
Dim FirstValue As Variant
Dim NewPermutations As Collection
Dim ResultCollection As Collection
Dim NewResultCollection As Collection

' See if there is only one value.
If CollectionsToPermute.Count = 1 Then
' Return a collection containing one permutation equal to the
single value.
Set ResultCollection = New Collection
ResultCollection.Add New Collection
ResultCollection.Item(1).Add CollectionsToPermute.Item(1)
Set GeneratePermutations = ResultCollection
Exit Property
End If

' Build permutations starting with each possible first item.
Set ResultCollection = New Collection
num_CollectionsToPermute = CollectionsToPermute.Count
For I = 1 To num_CollectionsToPermute
' Save this value.
FirstValue = CollectionsToPermute.Item(I)
' Remove the item.
CollectionsToPermute.Remove I
' Generate the permutations of the remaining
CollectionsToPermute.
Set NewPermutations =
GeneratePermutations(CollectionsToPermute)
' Make permutations by adding FirstValue to the beginning of
each of the new permutations.
For J = 1 To NewPermutations.Count
' Add the first item.
Set NewResultCollection = New Collection
NewResultCollection.Add FirstValue
' Add the rest of the items in the jth new permutation.
For K = 1 To NewPermutations(J).Count
NewResultCollection.Add NewPermutations(J).Item(K)
Next K
' Add this new permutation to the ResultCollection.
ResultCollection.Add NewResultCollection
Next J
' Restore the removed value.
If I > CollectionsToPermute.Count Then
CollectionsToPermute.Add FirstValue
Else
CollectionsToPermute.Add FirstValue, , I
End If
Next I
' Return the ResultCollection.
Set GeneratePermutations = ResultCollection
End Property

Nov 13 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sketcher | last post by:
Hi, I am trying to create a quiz, Code is as follows: <html> <head> <title>Quiz</title> </head> <BODY> <Center><TABLE cellSpacing=3 cellPadding=0 border=0>
5
by: Vandana Rola | last post by:
Hello Everyone, I am a beginner in Javascript.I want to create fun quiz tool using javascript (no database). The feature of that tool is every question has five choices. The user needs to select...
4
by: DAL | last post by:
I want to build my kid a program that cycles through questions (using a label for the question), and lets him choose one of two radio buttons for the right answer. How do I get every set of...
0
by: philip | last post by:
hello, i am now developing a quiz application for my school using ASP.NET and SQL SERVER 2005, here is a senario: It will have 20 students for taking a quiz in a classroom, they have to answer...
2
by: kenny | last post by:
I'm making a quiz to be posted on the internet. but I'm facing difficulties in finding a simple timer for the quiz (unlimited timing) which will keep on running regardless to the change of the page...
0
NoPeasHear
by: NoPeasHear | last post by:
I don't know what I am doing wrong... I used this tutorial... http://www.permadi.com/tutorial/flashMXQuiz/index.html It works with their quiz.xml file, but when I add an option for multiple...
3
by: Raqueeb Hassan | last post by:
Hello, I was helping one of my friend's school on setting up a online quiz system. They have the AMP systems to host php+mysql. The quiz script/software should have the following features: a....
5
nomad
by: nomad | last post by:
Hello Everyone: Just want to ask how easy would it be to build a quiz in Java. I have not use Java for a few months (5). Quiz would need the following: 1. T or F and mulitiple question, possible...
3
by: empiresolutions | last post by:
I am building a app that creates quizzes. This is how it goes - - Create Quiz - Provide up to 10 different types of Quiz Results - Give up to 50 Questions - Each Question has up to 10 possible...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.