Hi Tomek,

it may not be the most elegant solution but given that there are actually more than 10 questions a function that simply selects random questions until it has 10 of them will do the trick.

function local:selectX(\$x, \$selected) {
return if (\$x gt 0) then
let \$newQuestion := \$lectureColl/lecture/questions/question[position() eq <random number>]
return if (\$selected = \$newQuestion) then  local: select(\$x, \$selected) else   local: select(\$x - 1, \$selected | \$newQuestion)
else \$selected
};

Mind you, the above is not a working or even valid XQuery function, but the general idea is that the function takes a number and a sequence of nodes and simply keeps on adding nodes to the sequence until \$X < 0. For large sets of nodes this is probably faster than sorting the sequence with a random key and taking the first 10 nodes, as Chris mentioned.

Huib.

A classic approach to this random selection problem is to sort with a random
key:

( for \$question in \$lectureColl/lecture/questions/question
let \$r := util:random()
order by \$r
return \$question
) [position() <= 10]

By coincidence there has been some recent debate about methods to do this,
arising from the failure of the Microsoft random browser ordering and this
approach  is probably good enough but inefficient, especailly with large
pool of questions.

http://www.robweir.com/blog/2010/02/microsoft-random-browser-ballot.html

Chris

Tomek Piechowicz wrote:

Hi,
I have collection of questions, each question consist of <text> and <id>
nodes.I need to draw 10 random different(!) questions. I found some
solution that uses math:random() :

let \$questions := \$lectureColl/lecture/questions/question[round((\$qCount
div 100) div (math:random() * 100))]/id

and I could use it in for loop, but there are two problems :

1. Above construction sometimes returns no nodes.

2. I don`t know how to ensure that every drawn question id would be unique
?

Can anybody give me some tips how to deal with this problems ?