## exist-open

 [Exist-open] Drawing 10 random nodes. From: Tomek Piechowicz - 2010-02-27 21:36:28 ```Hi, I have collection of questions, each question consist of and 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 ? Regards, Tomek Piechowicz ```
 Re: [Exist-open] Drawing 10 random nodes. From: Chris Wallace - 2010-03-01 15:42:49 ```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 and > 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 ? > > Regards, > Tomek Piechowicz > > > ------------------------------------------------------------------------------ > Download Intel® Parallel Studio Eval > Try the new software tools for yourself. Speed compiling, find bugs > proactively, and fine-tune applications for parallel performance. > See why Intel Parallel Studio got high marks during beta. > http://p.sf.net/sfu/intel-sw-dev > _______________________________________________ > Exist-open mailing list > Exist-open@... > https://lists.sourceforge.net/lists/listinfo/exist-open > > -- View this message in context: http://old.nabble.com/Drawing-10-random-nodes.-tp27731180p27745179.html Sent from the exist-open mailing list archive at Nabble.com. ```