426,234 Members | 1,844 Online Need help? Post your question and get tips & solutions from a community of 426,234 IT Pros & Developers. It's quick & easy.

# randomising for a quiz

 P: n/a 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 Replies

 P: n/a This is math not a computer group. "WindAndWaves" 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

 P: n/a On Fri, 27 Aug 2004 15:14:52 +1200, "WindAndWaves" wrote: Dear AllI 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 fouranswers on the page in a randomized way (i.e. you have no idea which onecomes 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

 P: n/a 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" wrote in message news:dh********************************@4ax.com... On Fri, 27 Aug 2004 15:14:52 +1200, "WindAndWaves" wrote:Dear AllI 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 fouranswers on the page in a randomized way (i.e. you have no idea which onecomes 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

 P: n/a On Sat, 28 Aug 2004 00:21:41 +1200, "WindAndWaves" wrote: Dear MichaelI 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

 P: n/a That is a nice solution Michael, thank you for that idea. "Michael Gray" wrote in message news:d4********************************@4ax.com... On Sat, 28 Aug 2004 00:21:41 +1200, "WindAndWaves" wrote:Dear MichaelI 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

 P: n/a On Sun, 29 Aug 2004 08:46:02 +1200, "WindAndWaves" 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

 P: n/a Michael Gray wrote in message news:. .. On Sat, 28 Aug 2004 00:21:41 +1200, "WindAndWaves" wrote:Dear MichaelI 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

 P: n/a On 15 Sep 2004 19:21:56 -0700, dw*****@yahoo.com (David Bandel) wrote: Michael Gray wrote in message news:. .. On Sat, 28 Aug 2004 00:21:41 +1200, "WindAndWaves" 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 firstsecond 6 2 is firstetc.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
{"ft_lang_label":"__label__en","ft_lang_prob":0.6903402,"math_prob":0.8613084,"size":3450,"snap":"2019-26-2019-30","text_gpt3_token_len":821,"char_repetition_ratio":0.24405107,"word_repetition_ratio":0.07723577,"special_character_ratio":0.2005797,"punctuation_ratio":0.12349914,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9971948,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-07-24T07:36:49Z\",\"WARC-Record-ID\":\"<urn:uuid:7dc62821-4e70-4420-9573-7106eb2a9166>\",\"Content-Length\":\"60930\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:3faac48d-1236-44ff-b2f8-e49313cc05d2>\",\"WARC-Concurrent-To\":\"<urn:uuid:04a50bb0-2eeb-4ba4-be8e-158e13a24b75>\",\"WARC-IP-Address\":\"104.197.32.212\",\"WARC-Target-URI\":\"https://bytes.com/topic/access/answers/200436-randomising-quiz\",\"WARC-Payload-Digest\":\"sha1:P4XBOODLPM6LWJT5V3RKCYWQPJ42CJAP\",\"WARC-Block-Digest\":\"sha1:XHUYG7TY37DXR2FULJN6DT7UZMC57CXB\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-30/CC-MAIN-2019-30_segments_1563195531106.93_warc_CC-MAIN-20190724061728-20190724083728-00001.warc.gz\"}"}