Tip

Random Documents

Since there has been an influx of questions on how to make exams in Lotus Notes
with random questions..I figured I'd post my random document selector.

Things to note:
'total_questions' should be filled in programatically. It should reflect the
number of documents in your doc collection or view that you are going to select
docs from.

'how_many' is the number of random documents to select

Once you have run randomizer() the outlist array will contain the document
number to use in getnthdocument.
example usage:
forall x in outlist
doc = view.getnthdocument(x)
endforall

--or--
forall x in outlist
doc = collection.getnthdocument(x)
endforall

Any questions on this scripts can be sent to me at:
redline@thereeses.net
Custom test dbs can also be developed.. for a price of course ;-)
Option Public
Dim tarray() As Integer
Dim outlist() As Integer
Dim total_questions As Integer
Sub Initialize
Call randomizer()
End Sub
Function randomizer()
Dim anum As Integer
Dim how_many As Integer
Dim place As Integer

' Total number of questions to choose from
total_questions% = 50
' How many do you want?
how_many% = 10
Redim outlist(0 To (how_many%-1))
'Create number array
total_questions% = total_questions% -1
Redim tarray(0 To (total_questions%))
For x = 0 To (total_questions%)
tarray(x) = x+1
Next
'Now shuffle the numbers
For place = 0 To (how_many%-1)
anum% = Round(Rnd()*total_questions%,0)
outlist(place) = tarray(anum%)
Call reorg(anum%)
Next
End Function
Function reorg(place As Integer)
Dim x As Integer
'Remove selected and slide down rest
For x = place To (total_questions%-1)
tarray(x) = tarray(x+1)
Next
'Take one from total_questions
total_questions% = total_questions% -1
Redim Preserve tarray(0 To total_questions%)
End Function

This was first published in November 2000

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.