You are on page 1of 2

Hello World:

Hello World is usually the very first line of code that's written when you learn a
new language

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